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

How to make sounds play when a Bool Value is set to true?

So like in the title that's what I am trying to do, I have some code but it doesn't work...

if script.Parent.Parent.TESTING.Value == true then
script.Parent.Sound:Play()
elseif script.Parent.Parent.TESTING.Value == false then
script.Parent.Sound:Pause()
end

3 answers

Use :GetPropertyChangedSignal.

local Testing = script.Parent.Parent:WaitForChild("TESTING")

Testing:GetPropertyChangedSignal("Value"):Connect(function()

if Testing.Value == true then
script.Parent.Sound:Play()
elseif Testing.Value == false then
script.Parent.Sound:Pause()
end
end)

I bet you could use a loop to fix that, the code you have now only checks if the value is true once.

while true do
	wait()
	if script.Parent.Parent.TESTING.Value == true then
		script.Parent.Sound:Play()
	else -- you don't need an elseif because the only other possibility is false
		script.Parent.Sound:Pause()
	end
end

3 comments

0

i edited it to add a wait()

0

Use a PropertyChangedSignal instead.

0

thats probably better than what i did lol

if script.Parent.Parent.TESTING.Value == true then script.Parent.Sound.Playing = true elseif script.Parent.Parent.TESTING.Value == false then script.Parent.Sound.Playing = false end

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