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
10 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?

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)

4 answers

Log in to vote
0
Answered by 10 years ago
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)


Ad
Log in to vote
2
Answered by 10 years ago

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)


Log in to vote
1
Answered by 10 years ago

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.

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

I tried them all, none of them worked

Answer this question