Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago

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

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

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)
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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
0
i edited it to add a wait() Diamond52002 29 — 4y
0
Use a PropertyChangedSignal instead. Ziffixture 6913 — 4y
0
thats probably better than what i did lol Diamond52002 29 — 4y
Log in to vote
0
Answered by 4 years ago

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

Answer this question