You're doing too much, if you want the GUI to become invisible do this:
gui = script.Parent
gui.MouseButton1Click:connect(function()
if gui.Visible == true then gui.Visible = false else return end
end)
if you want to hide a set of GUIs you can do something like this:
gui = script.Parent
guisToHide = {gui1,gui2}
gui.MouseButton1Click:connect(function()
if gui.Visible == true then
gui.Visible = false
for _,c in pairs(guisToHide) do
c.Visible = false
end
end
end)
And since you also want to to only appear once, you could try:
gui = script.Parent
guisToHide = {gui1,gui2}
if not game.Players.LocalPlayer:FindFirstChild("Boolean") then
local bool = Instance.new("BoolValue",game.Players.LocalPlayer)
bool.Name = "Boolean"
else
gui.Visible = false
for _,c in pairs(guisToHide) do
c.Visible = false
end
end
gui.MouseButton1Click:connect(function()
if gui.Visible == true then
gui.Visible = false
for _,c in pairs(guisToHide) do
c.Visible = false
end
end
end)
Reference:
GUIButton
Button1Click
Tables
For loop
So, what did you do wrong?
Well,
On line one you made gui local. It's not in a function, every part of the code will be able to reference it, it should be public.
So you'd take the local away and make it
gui = script.Parent
On line two you call a method that doesn't exist. Mouse1Click is not a valid member of the GuiButton array.
GuiButton.MouseButton1Click(connect(function()
is what you meant.
on line 5 you made and attempt to reference a nil value. (It doesn't exist)
I fixed that by creating a value that is referenced. (I also made it to where it can only work once for you)
The rest is an attempt to make the gui invisible if it's clicked and already supposed to be invisible.
I fixed that by checking for the value that you used for the only once thing.
2 comments
Making gui local doesn't keep it from being used in the rest of the script if it isn't inside of anything.
Obviously? Making it local is pointless, which is why I removed it. Learn to read.