Hey everyone, so I am finishing up on my game right now. Just need to add a few finishing touches(It’s an obby) I wanted to add a button where if the person click on it, the GUI/UI visible will be false and they can’t see it. It seems to not work, I can’t find any type of error in my output. Here is my script.
local coil = game.StarterGui.CoilGamepass.Gamepass
local SkipStage = game.StarterGui.SkipStageGamepass.Gamepass
local MuteButton = game.StarterGui.MuteButton.Mute1
script.Parent.MouseButton1Click:Connect(function()
if coil.Visible == true and SkipStage.Visible == true and MuteButton.Visible == true then
coil.Visible = false
SkipStage.Visible = false
MuteButton.Visible = false
else
coil.Visible = true
SkipStage.Visible = true
MuteButton.Visible = true
end
end)
If anyone knows how to fix this, please leave a comment :)))
Your script does work, but the thing is: you are modifying the UI in game.StarterGui instead of PlayerGui. When a new Character instance is created, it will take the UI from game.StarterGui and copy it to game.Players.LocalPlayer.PlayerGui.
Along with those errors, the code under script.Parent.MouseButton1Click:Connect(function() can be simplified to a simple thing.Visible = not thing.Visible.
local coil = game.Players.LocalPlayer.PlayerGui.CoilGamepass.Gamepass
local SkipStage = game.Players.LocalPlayer.PlayerGui.SkipStageGamepass.Gamepass
local MuteButton = game.Players.LocalPlayer.PlayerGui.MuteButton.Mute1
script.Parent.MouseButton1Click:Connect(function()
coil.Visible = not coil.Visible
SkipStage.Visible = not SkipStage.Visible
MuteButton.Visible = not MuteButton.Visible
end
end)
You are trying to change a value from a button in StarterGUI.
Let me first explain what’s StarterGUI.
When a player joins the game, the game will automatically copy the guis in the StarterGUI to the player’s PlayerGUI.
Now, you have 2 choices here. You can basically put this local script in StarterPack(same as the StarterGUI but it copies everything in the StarterPack to the player’s Backpack.), or you can put this local script inside the button.
I’m going to show you an example of the StarterPack script.
local player = game.Players.LocalPlayer
local Button = player.PlayerGui.Button
local coil = player.PlayerGui.CoilGamepass.Gamepass
local SkipStage = player.PlayerGui.SkipStageGamepass.Gamepass
local MuteButton = player.PlayerGui.MuteButton.Mute1
Button.MouseButton1Click:Connect(function()
If coil.Visible == true and SkipStage.Visible == true and MuteButton.Visible == true then
coil.Visible = false
SkipStage.Visible = false
MuteButton.Visible = false
else
coil.Visible = true
SkipStage.Visible = true
MuteButton.Visible = true
end
end)
you can both put this inside the button and the starterpack.