Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago
Edited 5 years ago

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.

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... NorteX_tv 101 — 5y
0
(gui.Parent = ServerStorage, can't get player) NorteX_tv 101 — 5y
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. SummerEquinox 643 — 5y
0
Oh, and as capinbuilda mentioned - it makes a lot more sense to clone the GuiObject rather than just move it. SummerEquinox 643 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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)
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... PureGamerGames 16 — 5y
0
no, 'plr' is just a variable. you could put 'potato' there and it would work just the same SchonATL 15 — 5y
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). SummerEquinox 643 — 5y
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? PureGamerGames 16 — 5y
View all comments (2 more)
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. SummerEquinox 643 — 5y
0
why don't u just do Visible = not Visible HappyTimIsHim 652 — 5y
Ad

Answer this question