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

Playing music in different sound areas restarts the sound when jumping?

I was looking at alvinblox on youtube and he was explaining how to make music in different sound environments. However, I seen some flaws within the code with playing music.Whenever, I jump it re fires the code again and plays the music again. I just want the music to continue to play WITHOUT RESTARTING until we leave the brick. Thanks in advance.

script.Parent.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild('HumanoidRootPart') then
        game.Players[hit.Parent.Name].PlayerGui.Sound2:Stop()
        game.Players[hit.Parent.Name].PlayerGui.Sound1.Volume = 1
        game.Players[hit.Parent.Name].PlayerGui.Sound1:Play()

    end
end)

1 answer

✓ Accepted answer

Just use an infinite debounce

Debounce = true

script.Parent.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild('HumanoidRootPart') and Debounce then
	Debounce = false
        game.Players[hit.Parent.Name].PlayerGui.Sound2:Stop()
        game.Players[hit.Parent.Name].PlayerGui.Sound1.Volume = 1
        game.Players[hit.Parent.Name].PlayerGui.Sound1:Play()

    end
end)

If you want it to play again change the debounce back to true

1 comment

0

Thanks for your assistance, but it still continues to do the same thing, when I just it palys

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