My GUI's wont work and I need help

Hey developers of Roblox! I am fairly new to scripting and need some help with some GUI’s. I don’t know if this is obvious or not.

Basically the problem is when ever I wanna disable/enable a gui, It wont let me.

The code I use for it is this:

Lets say I am making a play button so I would do,

local play = game.StarterGui.play —the gui
local button = play.TextButton —the text button

button.MouseButton1Click:Connect(function()
play.Enabled = false
button.Visible = false
end)

Oh and by the way, there is nothing the comes up in the output. Like nothing at all.
But I remembered I have youtube! So i looked up on YouTube and saw a tutorial for a play button. It used the terms “script.Parent”

so then I remade my script like this.

local play = script.Parent.Parent – the gui
local button = script.Parent – text button

button.MouseButton1Click:Connect(function()
play.Enabled = false
button.Visible = false
end)

and it worked. So I was wondering what was I doing wrong in the original script? Was it the referencing or what? I am very confused and can someone please help me since it is getting hard put children in the right frames and labels to reference them properly. I would really appreciate if you help!:grin::pray:
(they were all local scripts and sorry if this was long)

image

image

It was the path. You must hook up the function to the one in PlayerGui, not StarterGui. Players only see the one in PlayerGui, which is cloned from StarterGui.

1 Like

So do I put the GUI in playerGui’s?

1 Like

No, you put the GUIs in StarterGui which will then be cloned to the clients when they join or die.

1 Like

But why did

local play = game.StarterGui.play
local button = play.TextButton

button.MouseButton1Click:Connect(function()
play.Enabled = false
button.Visible = false
end)

not work?
I feel stupid

Because even if the GUI is cloned to PlayerGui, it will still reference the GUI in StarterGui.

So what would the correct script be?

The latter one you displayed which uses the Parent property.

1 Like

No other way? But thank you very much I appreciate your help ALOT I didnt think I would get a super fast reply. Lol

Like Vong said you have to reference the playergui not the startergui. The alternative would be-

local play = game.Players.LocalPlayer.PlayerGui.play

1 Like

Thanks since I wasn’t sure what to do. The script.Parent would have been a pretty complicated way of doing things since I would have to put the Children in the right places for it to work instead of just refrencing them normally.

How the StarterGui works is it clones all the children under it and places it in a new container under LocalPlayer.PlayerGui.

So what is happening is you are referencing an entirely different gui than the one you are seeing. You will see this is true if you go to the Explorer while in Play Solo and finding the different sets of gui’s, under StarterGui and Players > musman65 > PlayerGui.

2 Likes

Thanks a lot! I really appreciate all of your guy’s help. This is basically summing up everything that’s been said but with a bit more too it. Ill put this as a solution for everyone too see but if I could put more solution I would put all of them for the players to read and understand it well and fully.

3 Likes

Wait i still have one question. How would I make it so that the script goes into the player’s gui’s

game.Players.???.PlayerGui.play ?
Sorry for asking again im just really confused
Like instead of saying the player’s name, because I don’t know who’s gonna click it how would I generalize.

1 Like

You would use the LocalPlayer property from Players, it will give you the current client’s player.

game.Players.LocalPlayer.PlayerGui.play

You can view more properties of Players from the dev hub.

1 Like

You should keep in mind that this only works on LocalScripts, because LocalPlayer is not replicated to the server.

2 Likes