How to make this script do the next line of code when clicked again?
script.Parent.MouseButton1Click:Connect(function()
game.Workspace.Scripts.GameScripts.BackgroundSound.Disabled = true
game.Workspace.Scripts.GameScripts.BackgroundSound.Sound.Volume = 0
script.Parent.Text = 'BACKGROUND SOUND OFF'
end)
I know how to reverse the code that does the stuff, but I don’t know how to make it do the opposite lines of code when clicked again
local toggle = false
script.Parent.MouseButton1Click:Connect(function()
if not toggle then
toggle = true
game.Workspace.Scripts.GameScripts.BackgroundSound.Disabled = true
game.Workspace.Scripts.GameScripts.BackgroundSound.Sound.Volume = 0
script.Parent.Text = 'BACKGROUND SOUND OFF'
elseif toggle then
toggle = false
game.Workspace.Scripts.GameScripts.BackgroundSound.Disabled = false
game.Workspace.Scripts.GameScripts.BackgroundSound.Sound.Volume = 1
script.Parent.Text = 'BACKGROUND SOUND ON'
end
end)
I assume you’re trying to make it toggle between states, here you go.
mc3334
(mc3334)
November 14, 2021, 11:36pm
4
simplified to:
local toggle = false
script.Parent.MouseButton1Click:Connect(function()
toggle = not toggle
game.Workspace.Scripts.GameScripts.BackgroundSound.Disabled = not toggle
game.Workspace.Scripts.GameScripts.BackgroundSound.Sound.Volume = toggle and 1 or 0
script.Parent.Text = "BACKGROUND SOUND "..(toggle and "ON" or "OFF")
end)
1 Like