|
| 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 |
|
|
|
| 10 Jun 2014 02:49 PM |
The exact error:
Players.Player2.PlayerGui.GameOverGui:2: attempt to index local 'gui' (a nil value) |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 10 Jun 2014 03:01 PM |
| I...Am...Using a RemoteEvent... :/ |
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 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
|
  |
| Joined: 30 Jul 2012 |
| Total Posts: 1446 |
|
| |
|
|
| 10 Jun 2014 03:07 PM |
remote function remote function remote function |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| Joined: 30 Jul 2012 |
| Total Posts: 1446 |
|
| |
|
|
| 10 Jun 2014 03:12 PM |
| Very well...I will try this using a RemoteFunction to create the Gui. |
|
|
| Report Abuse |
|
|
|
| 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
|
  |
| Joined: 30 Jul 2012 |
| Total Posts: 1446 |
|
|
| 10 Jun 2014 03:16 PM |
| show me where u defined gui |
|
|
| Report Abuse |
|
|
|
| 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
|
  |
| Joined: 30 Jul 2012 |
| Total Posts: 1446 |
|
|
| 10 Jun 2014 03:20 PM |
| make sure gui isn't in a different scope |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 10 Jun 2014 03:21 PM |
| "gui" is in the proper scope for that event firing. |
|
|
| Report Abuse |
|
|
|
| 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
|
  |
| 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
|
  |
| 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 |
|
|