Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Clicking on a surface GUI to produce a Screen GUI. Not working?

Hello, I am trying to make a Screen GUI pop up when a player clicks a button in a Surface GUI however when testing the script out it does not pop up and returns an error that 'plr' is a nill value.

This is my code...

local gui = game.ServerStorage.notes

script.Parent.MouseButton1Click:Connect(function (plr)
	print("click")
    gui.Parent = plr.PlayerGui
end)

And it outputs this when I click on the button.

17:30:53.589 -Workspace.Pure.dispatcher.desk.monitor.screen.SurfaceGui.welcome.notes.Script:5: attempt to index local 'plr' (a nil value)

17:30:53.590 - Stack Begin

17:30:53.590 - Script 
'Workspace.Pure.dispatcher.desk.monitor.screen.SurfaceGui.welcome.notes.Script', Line 5

17:30:53.591 - Stack End

Thanks for any help.

4 comments

0

gui.Parent of game.ServerStorage.notes is just returning ServerStorage I think. You can't get player from ServerStorage, as it's server sided. If you need played, you'll need either a LocalScript or any event that has player, e.g. PlayerAdded (plr) or Touched (hit.Parent). To make this script work as it is, you should be looping through players and getting the right one, but I don't know how...

0

(gui.Parent = ServerStorage, can't get player)

0

Hierarchically is this script somewhere inside of the client's UI? Additionally, MouseButton1Click does not automatically pass a player argument as you seem to think it does (which is why your error occurs), if this is a LocalScript (and it should be) - set the parent to LocalPlayer's PlayerGui.

0

Oh, and as capinbuilda mentioned - it makes a lot more sense to clone the GuiObject rather than just move it.

1 answer

✓ Accepted answer

Hey, try adding :Clone() to Line 1. As it is right now, it is just relocating the GUI, not creating a separate one then moving it. This might be your issue. Also, make sure capitalization is the same on the script as it is in the Explorer.

local gui = game.ServerStorage.notes:Clone()

script.Parent.MouseButton1Click:Connect(function(plr)
    print("click")
    gui.Parent = plr.PlayerGui
end)

6 comments

0

Hello, I tried adding the :clone however it returned the same error. I also made sure the capitalisation was right too. The only solution I could think was maybe the 'plr' but not being right...

0

no, 'plr' is just a variable. you could put 'potato' there and it would work just the same

0

That's a non-point anyway because MouseButton1Click doesn't automatically pass any variables. plr = nil because plr ~= LocalPlayer. All that needs to be changed is setting the parent to LocalPlayer's PlayerGui (aside from the cloning which you mentioned).

0

I have modified the script so that local plr = game.Players.LocalPlayer however it still returns the same error. Do I have to use some sort of local script?

0

You HAVE to use a LocalScript... if you're using a classic Script then that immediately creates an issue since you are dealing with UI interaction.

0

why don't u just do Visible = not Visible

This discussion is preserved as it was. New answers, comments, and votes are closed.