local Volume = game.Workspace.Sound.Volume script.Parent.MouseButton1Click:connect(function() if Volume = 0.2 then Volume = 0 elseif Volume = 0 then Volume = 0.2 end end)
Volume
variable is a reference to the actual property of the Sound
. If the volume of the Sound
changes, the variables you have defined won't update; only its Volume
property will change. In order to fix this, you can remove the Volume
variable and only make direct accesses to the Volume
property of the Sound
. You could also modify the variables to hold the Sound
object itself.local Sound = game.Workspace.Sound script.Parent.MouseButton1Click:Connect(function() -- :connect is deprecated, use :Connect if Sound.Volume == 0.2 then Sound.Volume = 0 elseif Sound.Volume == 0 then Sound.Volume = 0.2 end end)
And as previously mentioned by brokenrares, you need double equals in conditionals.
Basically you're not using the if statement in the right way. You're checking if the Volume is 0.2 but you'll have to use double '=' for that since it's inside an if statement So:
local Volume = game.Workspace.Sound.Volume script.Parent.MouseButton1Click:connect(function() if Volume == 0.2 then Volume = 0 elseif Volume == 0 then Volume = 0.2 end end)