generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Pass Instance as Argument to RemoteEvent, Comes Back as Nil?

Previous Thread :: Next Thread 
CodeTheorem is not online. CodeTheorem
Joined: 03 Jun 2009
Total Posts: 2771
10 Jun 2014 02:47 PM
I'm writing a script to send a GUI that is prepared on the server to players using a RemoteEvent. For some reason, the LocalScript on the client is giving me an error indicating that the GUI is nil?

Here is a line from my script in ServerScriptService:

--The variable "gui" is properly set to an actual instance of a ScreenGui
game.ReplicatedStorage.CubeRemoteEvents.GameOverGuiCreated:FireAllClients(gui:clone())


And here's the LocalScript:

game.ReplicatedStorage.CubeRemoteEvents.GameOverGuiCreated.OnClientEvent:connect( function(gui)
gui.Parent = script.Parent
if script.Parent:FindFirstChild("GameplayHUD") then
script.Parent.GameplayHUD:Destroy()
end
end)
Report Abuse
CodeTheorem is not online. CodeTheorem
Joined: 03 Jun 2009
Total Posts: 2771
10 Jun 2014 02:49 PM
The exact error:

Players.Player2.PlayerGui.GameOverGui:2: attempt to index local 'gui' (a nil value)
Report Abuse
FearMeIAmLag is not online. FearMeIAmLag
Joined: 02 Jun 2012
Total Posts: 1748
10 Jun 2014 02:57 PM
try adding "wait(1)" to the top of the localscript. Sometimes the client has a bit of a loading lag and the wait should adjust for that. It's quite common, so try to add the wait to all of your localscripts.
Report Abuse
CodeTheorem is not online. CodeTheorem
Joined: 03 Jun 2009
Total Posts: 2771
10 Jun 2014 02:59 PM
That...Shouldn't happen, though...If I'm firing a client event...
Ugh, I'm hoping you're wrong, but if not, thanks. But if you are right, then hey, ROBLOX, FIX IT!
Report Abuse
L0cky2013 is not online. L0cky2013
Joined: 30 Jul 2012
Total Posts: 1446
10 Jun 2014 03:00 PM
Use a remote event for this cause, they allow a value to be returned.
Report Abuse
CodeTheorem is not online. CodeTheorem
Joined: 03 Jun 2009
Total Posts: 2771
10 Jun 2014 03:01 PM
I...Am...Using a RemoteEvent... :/
Report Abuse
L0cky2013 is not online. L0cky2013
Joined: 30 Jul 2012
Total Posts: 1446
10 Jun 2014 03:03 PM
function* but I only read ur title when I posted that lol.
Report Abuse
CodeTheorem is not online. CodeTheorem
Joined: 03 Jun 2009
Total Posts: 2771
10 Jun 2014 03:03 PM
This is the LocalScript now. It no longer fires an error, but it does not work.

game.ReplicatedStorage.CubeRemoteEvents.GameOverGuiCreated.OnClientEvent:connect(function(gui)
local waits = 0
repeat
wait(0.1)
waits = waits + 1
until waits == 10 or gui
if not gui then
return
end

gui.Parent = script.Parent
if script.Parent:FindFirstChild("GameplayHUD") then
script.Parent.GameplayHUD:Destroy()
end
end)
Report Abuse
L0cky2013 is not online. L0cky2013
Joined: 30 Jul 2012
Total Posts: 1446
10 Jun 2014 03:06 PM
try..a..remote..function
Report Abuse
JoshuaKempfert is not online. JoshuaKempfert
Joined: 16 Feb 2013
Total Posts: 2407
10 Jun 2014 03:07 PM
remote function
remote function
remote function
Report Abuse
FearMeIAmLag is not online. FearMeIAmLag
Joined: 02 Jun 2012
Total Posts: 1748
10 Jun 2014 03:07 PM
I meant just do this:

wait(1)
game.ReplicatedStorage.CubeRemoteEvents.GameOverGuiCreated.OnClientEvent:connect( function(gui)
gui.Parent = script.Parent
if script.Parent:FindFirstChild("GameplayHUD") then
script.Parent.GameplayHUD:Destroy()
end
end)

I'm not certain it will fix your problem, but it should help. Just try it and it may work. You never know.
Report Abuse
CodeTheorem is not online. CodeTheorem
Joined: 03 Jun 2009
Total Posts: 2771
10 Jun 2014 03:08 PM
I don't want to use a RemoteFunction because then if a user's LocalScript breaks, it will break the entire game. All I want to do is pass a ScreenGui into a RemoteEvent handler as an argument.
Report Abuse
CodeTheorem is not online. CodeTheorem
Joined: 03 Jun 2009
Total Posts: 2771
10 Jun 2014 03:08 PM
@FearMeIAmLag: It's connecting just fine! It's just not getting anything in the value of the parameter "gui."
Report Abuse
L0cky2013 is not online. L0cky2013
Joined: 30 Jul 2012
Total Posts: 1446
10 Jun 2014 03:11 PM
still shouldn't break
Report Abuse
CodeTheorem is not online. CodeTheorem
Joined: 03 Jun 2009
Total Posts: 2771
10 Jun 2014 03:12 PM
Very well...I will try this using a RemoteFunction to create the Gui.
Report Abuse
FearMeIAmLag is not online. FearMeIAmLag
Joined: 02 Jun 2012
Total Posts: 1748
10 Jun 2014 03:15 PM
You could've also spelled something wrong. Try checking the spelling if you can't figure it out.
Report Abuse
L0cky2013 is not online. L0cky2013
Joined: 30 Jul 2012
Total Posts: 1446
10 Jun 2014 03:16 PM
show me where u defined gui
Report Abuse
CodeTheorem is not online. CodeTheorem
Joined: 03 Jun 2009
Total Posts: 2771
10 Jun 2014 03:19 PM
local gameovergui = game.ServerStorage.GameOverGui
--Then there's stuff in between
local gui = gameovergui:clone()
--In between, I do a bunch of property changes on the gui
game.ReplicatedStorage.CubeRemoteEvents.GameOverGuiCreated:FireAllClients(gui:clone())
Report Abuse
L0cky2013 is not online. L0cky2013
Joined: 30 Jul 2012
Total Posts: 1446
10 Jun 2014 03:20 PM
make sure gui isn't in a different scope
Report Abuse
CodeTheorem is not online. CodeTheorem
Joined: 03 Jun 2009
Total Posts: 2771
10 Jun 2014 03:20 PM
Using a RemoteFunction to return the Instance of the ScreenGui gave me the same result - a nil value.
Report Abuse
FearMeIAmLag is not online. FearMeIAmLag
Joined: 02 Jun 2012
Total Posts: 1748
10 Jun 2014 03:20 PM
I thought :Clone() had to be capitalized? I'm pretty sure it has to, but I may be wrong.
Report Abuse
CodeTheorem is not online. CodeTheorem
Joined: 03 Jun 2009
Total Posts: 2771
10 Jun 2014 03:21 PM
"gui" is in the proper scope for that event firing.
Report Abuse
CodeTheorem is not online. CodeTheorem
Joined: 03 Jun 2009
Total Posts: 2771
10 Jun 2014 03:22 PM
:Clone(), :Destroy(), :Remove(), :FindFirstChild(), etc. All of those methods are case-insensitive. I've always used lower case names for them.
Report Abuse
L0cky2013 is not online. L0cky2013
Joined: 30 Jul 2012
Total Posts: 1446
10 Jun 2014 03:27 PM
I believe the error is not in the code snippet that you posted. I copied your code, optimized a test place to run with it, and it worked perfectly with a BasePlate instead of a gui.
Report Abuse
L0cky2013 is not online. L0cky2013
Joined: 30 Jul 2012
Total Posts: 1446
10 Jun 2014 03:28 PM
One other thing I can think of, make sure that the gui instance is archivable.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image