Im new to lua and I need help. Im trying to make a script where if I click something it will open the gui, if its already open then it will close.
How can I get this to work?
game = Game.StarterGui.ScreenGui game2 = Game.StarterGui.ScreenGui2 open = false function onButtonClicked() if open == false then game2.Frame.Visible = true else game2.Frame.Visible = false end end script.Parent.MouseButton1Down:connect(onButtonClicked)
player = game.Players.LocalPlayer game = player.PlayerGui.ScreenGui game2 = player.PlayerGui.ScreenGui2 open = false function onButtonClicked() if open == false then game2.Frame.Visible = true else game2.Frame.Visible = false end end script.Parent.MouseButton1Down:connect(onButtonClicked)
Try this.
game = player.PlayerGui.ScreenGui game2 = player.PlayerGui.ScreenGui2 function onButtonClicked() game2.Frame.Visible = not game2.Frame.Visible --make it the opposite of what it is end script.Parent.MouseButton1Down:connect(onButtonClicked)
I personally use boolean toggles for these sorts of things. To make one simply do this:
game = Game.StarterGui.ScreenGui game2 = Game.StarterGui.ScreenGui2 open = false function onButtonClicked() open = not open; if open then game2.Frame.Visible = true else game2.Frame.Visible = false end end script.Parent.MouseButton1Down:connect(onButtonClicked)
Edit: The other guy had a good idea. I suggest using that.