How do I make a GUI appear when you click it, and disappear when you click it again?

Hi! I am trying to make it so the GUI disappear the second time you click it. (it opens the first time you click it). I thought that if I added an “if” it would work, but instead it just stays open instead of staying shut at the beginning.

“Info” is the image of info, and “OpenInfo” is the button!

Thank you for helping me :smile:

local OpenInfo  = script.Parent

Info.Visible = false
OpenInfo.Visible = true

script.Parent.MouseButton1Click:Connect(function()

   Info.Visible = true
  

end)

if Info.Visible = true
script.Parent.MouseButton1Click:Connect(function()

Info.Visible = false

)
4 Likes

A neat trick for toggling a boolean value is

a = not a

It works because it sets a to the opposite of what it currently is. If a is true then it becomes false since not a is false. The reverse works too: if a were to be false then it would become true.

script.Parent.MouseButton1Click:Connect(function()
   Info.Visible = not Info.Visible
end)
7 Likes

When you click it, you check if its already enabled.

script.Parent.MouseButton1Click:Connect(function()
if --[[Reference the GUI here]].Enabled then
--do stuff
end
end)
1 Like