GUI not closing when Clicking on a button

The GUI is not closing when Clicking on a button.
and the open button is not getting visible

Code
local close = game.StarterGui.ScreenGui.X
local gui = game.StarterGui.ScreenGui
local Black = game.StarterGui.ScreenGui.TextButton
local Blue = gui.TextButton2
local Orange = gui.Textbutton3
local Open = gui.Open

close.MouseButton1Click:Connect(function()
	Black.Visible = false 
	Blue.Visible = false
	Orange.Visible = false
	print("closed")
	Open.Visible = true
end)

I’m really new. So Please point out any mistakes or tips to become better
Thanks!

1 Like

You should use PlayerGui instead of StarterGui since all contents of the StarterGui are being cloned to the StarterGui when a player joins the game.

local player = game.Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local close = playerGui.ScreenGui.X
local gui = playerGui.ScreenGui
local Black = playerGui.ScreenGui.TextButton
local Blue = gui.TextButton2
local Orange = gui.Textbutton3
local Open = gui.Open

close.MouseButton1Click:Connect(function()
	Black.Visible = false 
	Blue.Visible = false
	Orange.Visible = false
	print("closed")
	Open.Visible = true
end)
2 Likes

What’s the difference between playerGui and ScreenGui?
also I don’t really know about WaitForChild n stuff
also Thank you Sir

I assume you meant StarterGui not ScreenGui. As the wiki says:

The PlayerGui object is a container that holds a Player 's user GUI. If a ScreenGui is a descendant of a PlayerGui, then any GuiObject inside of the ScreenGui will be drawn to the player’s screen. Any LocalScript will run as soon as it is inserted into a PlayerGui.

And you can read about StarterGui here.

Basically, when a player joins the game the content in StarterGui is being cloned into the PlayerGui.

Oh Yea I’m just a bit confused. Also I don’t understand Wiki’s way of explaining things. If you could explain me that in simple words. Then I would be really thankful, Sir.

I have edited my responses a bit.

So basically the whole server won’t see what Player1 is seeing.

Yes, exactly. PlayerGui is unique for each player.

Oh I get it now. I’m so dumb xD.
Thank you Sir for helping me out!

You are welcome! I am glad I helped :slight_smile:.

Also Whenever I’m scripting and I Don’t know what button I press it triggers this annoying thing


See the white thing ? it’s so annoying

Insert button does that, press insert again to disable it.

2 Likes

Hmm, I honestly have no idea why. I have encoutered it a few times yet I still don’t know what it is.

Omg. Thank you dude like seriously thank you.
It was so annoying. but thank god you’re here to help me

It’s giving me an error

[PlayerGui is not a valid member of DataModel]

Nvm I Fixed it!
Thank you. :grinning:

You asked for tips and one I have is actually utilize the variables you make. For example, you have gui set, but you don’t use it in Black.

The other thing to consider is using a frame that will allow you to set the visibility of one element that will affect the ones within it. This saves setting each and every element.

1 Like

Oh thank you Sir for the nice tip!
:grinning: