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)
What is wrong with this music playing script that I made?
2 answers
###The problem lies in the fact that you wrongly assume that the 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)
1 comment
Thanks man.
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
Thanks, also I was wondering what the "Sound.---" would be for stopping a sound (so Sound.Play() to play, what for stop?)
Hi Fewice the function is Sound:Stop()
Hm, I thought it was that but it didnt work haha, ty.