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

Button only triggable every 3 seconds?

hi i want a button that only can be triggable every 3 seconds with clickdetector plz help:)

2 answers

✓ Accepted answer

This can be solved with debounce!

debounce is a variable that is set to true or false at the start of a script, Example:

local debounce = false

If you want your button to be triggerable every 3 seconds, simply make an if statement at the begginging of the function, wait(3) and change the value of debounce.

local debounce = false

function ButtonPress()
if debounce == false then
debounce = true
-- PUT OTHER STUFF HERE
wait(3)
debounce = false
end
end

script.Parent.ClickDetector.MouseClick:connect(ButtonPress)

And thats it, you can also check debounce in the scripting glossary on the website!

1 comment

0

okay

You can use the debounce method:

local cooldown = false

script.Parent.ClickDetector.MouseClick:connect(function()
	if not cooldown then
		--Do your stuff here
		cooldown = true
		wait(3)
		cooldown = false
	end
end)

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