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

How To Add In A Wait Before The Sound Play Again?

Asked by
ImfaoXD 158
8 years ago

Can somebody help me add in a wait? When I touch the brick, the sound play and it work but I don't want someone to just keep touching the brick over and over without waiting for a second or so to make the sound play again. It also lag too and I don't know why...

script.Parent.Touched:connect(function()
    script.Parent.Sound:Play()
end)

1 answer

Log in to vote
0
Answered by 8 years ago

Use a debounce.

This is simple. We're just going to make a bool variable, and if the variable is true, then we play the sound and make the variable false, wait a while, and make it true again.

Example,

local Debounce = true
script.Parent.Touched:connect(function()
    if Debounce then
        Debounce = false
        script.Parent.Sound:Play()
        wait(5)-- Wait As long as you want
        Deounce = true
    end
end)

Good Luck!

If I helped, please don't forget to accept my answer.
0
Thank you so much! ;) ImfaoXD 158 — 8y
0
np User#11440 120 — 8y
Ad

Answer this question