Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I open and close guis?

Asked by
dreamy67 135
11 years ago

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?

01game = Game.StarterGui.ScreenGui
02game2 = Game.StarterGui.ScreenGui2
03open = false
04 
05 
06function onButtonClicked()
07if open == false then
08    game2.Frame.Visible = true
09else
10    game2.Frame.Visible = false
11end
12end
13script.Parent.MouseButton1Down:connect(onButtonClicked)

4 answers

Log in to vote
0
Answered by 11 years ago
01player = game.Players.LocalPlayer
02game = player.PlayerGui.ScreenGui
03game2 = player.PlayerGui.ScreenGui2
04open = false
05 
06 
07function onButtonClicked()
08if open == false then
09    game2.Frame.Visible = true
10else
11    game2.Frame.Visible = false
12end
13end
14script.Parent.MouseButton1Down:connect(onButtonClicked)
Ad
Log in to vote
2
Answered by 11 years ago

Try this.

1game = player.PlayerGui.ScreenGui
2game2 = player.PlayerGui.ScreenGui2
3 
4function onButtonClicked()
5    game2.Frame.Visible = not game2.Frame.Visible --make it the opposite of what it is
6end
7script.Parent.MouseButton1Down:connect(onButtonClicked)
Log in to vote
1
Answered by 11 years ago

I personally use boolean toggles for these sorts of things. To make one simply do this:

01game = Game.StarterGui.ScreenGui
02game2 = Game.StarterGui.ScreenGui2
03open = false
04 
05 
06function onButtonClicked()
07    open = not open;
08    if open then
09        game2.Frame.Visible = true
10    else
11        game2.Frame.Visible = false
12    end
13end
14script.Parent.MouseButton1Down:connect(onButtonClicked)

Edit: The other guy had a good idea. I suggest using that.

Log in to vote
0
Answered by
dreamy67 135
11 years ago

I tried them all, none of them worked

Answer this question