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

How do I add a cool down on a button?

Asked by 4 years ago

OK so I'm making a door that's locked and it plays a sound when you touch it, but when you touch it once it plays the sound multiple times.

Music = script.Sound 
script.Parent.Touched:connect(function(hit)
    Music:Play()
    wait(5.5)
    Music:Stop()
end)



1 answer

Log in to vote
0
Answered by 4 years ago

You'd use what is called a "debounce"

Music = script.Sound
local debounce = false
script.Parent.Touched:connect(function(hit)
    if debounce == false then --if debounce is false
        debounce = true --Sets it to true
            Music:Play()
            wait(5.5)
        debounce = false --turns it back to false 
            Music:Stop()

    end
end)




1
It worked, thanks! Uniplier 83 — 4y
1
Uniplier, if it worked, accept the answer. LennyPlayzYT 269 — 4y
Ad

Answer this question