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

Button only triggable every 3 seconds?

Asked by
Filipalla 504 Moderation Voter
7 years ago

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

2 answers

Log in to vote
1
Answered by
jacobwow 140
7 years ago
Edited 7 years ago

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!

0
okay Filipalla 504 — 7y
Ad
Log in to vote
0
Answered by
itsJooJoo 195
7 years ago

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)

Answer this question