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

How to put cooldown on a button?

Asked by 9 years ago

Hey, How would I put a cooldown on a button, like, force the player to wait 10 seconds before the function of the button works again?

Thanks!

2 answers

Log in to vote
2
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

This method in general is usually called a debounce.

The basic idea is that you keep track of some state of whether or not its enabled.

Whenever the event happens (like pressing the button) you mark it as disabled. After the time is up, you re-enable it.

That will end up looking something like this:

coolingDown = false

function event()
    if not coolingDown then
        -- Do whatever else
        -- Do whatever else
        --
        coolingDown = true
        wait(10)
        coolingDown = false
    end
end

-- calls / connections to `event`
Ad
Log in to vote
-3
Answered by 9 years ago

At the very end of your script before the run command make a wait(10) command and insert any number you want in the parenthesis.

Answer this question