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

Why is this sound playing even though my value is set to false?

The sound plays even if my value is set to false. How can I possible fix this?

repeat wait()

	Button = script.Parent

until

Button.MouseButton1Down:connect(function(purchase)

local Sound = Instance.new("Sound")                 --The Cha-Ching Sound

			Sound.SoundId = "http://www.roblox.com/asset/?id=131886985"

			Sound.Parent = game.Lighting
			
			
			local SoundToggle = script.Parent.Parent.Parent.SoundOnOff			
			
			if SoundToggle.Value == true then

				if Sound.IsPlaying then

					Sound:Stop()

				else

					Sound:Play()

				end

			elseif SoundToggle.Value == false then

				--Sound Should Not Play If SoundToggle Value Is False

			end

end)

1 answer

✓ Accepted answer

Try this,

local Button = script.Parent
local SoundToggle = script.Parent.Parent.Parent.SoundOnOff  

local Sound = Instance.new("Sound") 
Sound.SoundId = "http://www.roblox.com/asset/?id=131886985"
Sound.Parent = game:GetService("SoundService")     

Button.MouseButton1Down:connect(function(purchase)
	if SoundToggle.Value then
		Sound:Play()
	else
		Sound:Stop()
	end
end)

Let me know if you need anything else

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