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
9 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.

1script.Parent.MouseButton1Click:connect(function ()
2if script.Parent.Text == "Hide Game" then
3game.StarterGui.Game.Background = false
4script.Parent.Text = "Show Game"
5else
6game.StarterGui.Game.Background = false
7script.Parent.Text = "Hide Game"
8end
9end)`

I've already tried:

1script.Parent.MouseButton1Click:connect(function ()
2if script.Parent.Text == "Hide Game" then
3game.Players.LocalPlayer.PlayerGui.Game.Background = false
4script.Parent.Text = "Show Game"
5else
6game.Players.LocalPlayer.PlayerGui.Game.Background = false
7script.Parent.Text = "Hide Game"
8end
9end)`

2 answers

Log in to vote
0
Answered by 9 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:

1script.Parent.MouseButton1Click:connect(function ()
2    if script.Parent.Text == "Hide Game" then
3        game.Players.LocalPlayer.PlayerGui.Game.Background.Visible = false
4        script.Parent.Text = "Show Game"
5    else
6        game.Players.LocalPlayer.PlayerGui.Game.Background.Visible = true
7        script.Parent.Text = "Hide Game"
8    end
9end)

Hope this helped.

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

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

01script.Parent.MouseButton1Click:connect(function ()
02    if script.Parent.Text == "Hide Game" then
03        game.Players.LocalPlayer.PlayerGui.Game.Background.Visible = false
04        script.Parent.Text = "Show Game"
05    else
06        game.Players.LocalPlayer.PlayerGui.Game.Background.Visible = true
07        script.Parent.Text = "Hide Game"
08    end
09end)
10 
11script.Parent.MouseButton1Click:connect(onClicked)

Answer this question