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

How do I add a cool down on a button?

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

✓ Accepted answer

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)




2 comments

1

It worked, thanks!

1

Uniplier, if it worked, accept the answer.

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