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.

1Music = script.Sound
2script.Parent.Touched:connect(function(hit)
3    Music:Play()
4    wait(5.5)
5    Music:Stop()
6end)

1 answer

Log in to vote
0
Answered by 4 years ago

You'd use what is called a "debounce"

01Music = script.Sound
02local debounce = false
03script.Parent.Touched:connect(function(hit)
04    if debounce == false then --if debounce is false
05        debounce = true --Sets it to true
06            Music:Play()
07            wait(5.5)
08        debounce = false --turns it back to false
09            Music:Stop()
10 
11    end
12end)
1
It worked, thanks! Uniplier 83 — 4y
1
Uniplier, if it worked, accept the answer. LennyPlayzYT 269 — 4y
Ad

Answer this question