Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why wont this button work?

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

✓ Accepted answer

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.

1 comment

0

Thanks it worked!

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.