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!
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)
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.
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.
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.