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

Why wont this button work?

Asked by
Aepeus 59
8 years ago

Im trying to make a button that hides a whole gui for my clicker game so i can make a sword fighting room.

script.Parent.MouseButton1Click:connect(function ()
if script.Parent.Text == "Hide Game" then
game.StarterGui.Game.Background = false
script.Parent.Text = "Show Game"
else
game.StarterGui.Game.Background = false
script.Parent.Text = "Hide Game"
end
end)`

I've already tried:

script.Parent.MouseButton1Click:connect(function ()
if script.Parent.Text == "Hide Game" then
game.Players.LocalPlayer.PlayerGui.Game.Background = false
script.Parent.Text = "Show Game"
else
game.Players.LocalPlayer.PlayerGui.Game.Background = false
script.Parent.Text = "Hide Game"
end
end)`

2 answers

Log in to vote
0
Answered by 8 years ago

I don't know what you are trying to do with game.Players.LocalPlayer.PlayerGui.Game.Background = false.

If Background is a part of the gui, you probably want to make it's property Visible to false when you want to hide it and to true when you want to show it, like this:

script.Parent.MouseButton1Click:connect(function ()
    if script.Parent.Text == "Hide Game" then
        game.Players.LocalPlayer.PlayerGui.Game.Background.Visible = false
        script.Parent.Text = "Show Game"
    else
        game.Players.LocalPlayer.PlayerGui.Game.Background.Visible = true
        script.Parent.Text = "Hide Game"
    end
end)

Hope this helped.

0
Thanks it worked! Aepeus 59 — 8y
Ad
Log in to vote
-1
Answered by 8 years ago

But you also have to add the ending right? Like this.

script.Parent.MouseButton1Click:connect(function ()
    if script.Parent.Text == "Hide Game" then
        game.Players.LocalPlayer.PlayerGui.Game.Background.Visible = false
        script.Parent.Text = "Show Game"
    else
        game.Players.LocalPlayer.PlayerGui.Game.Background.Visible = true
        script.Parent.Text = "Hide Game"
    end
end)

script.Parent.MouseButton1Click:connect(onClicked)

Answer this question