I am attempting to create a cooldown system for attacks(with weapons.). E.g, in the game Among Us, player kills a innocent, and has a 10second cooldown before they can kill again.
I have seen various other posts, but I want to ask for the most efficient way to do it, e.g without using wait() and while loops.
I have already half completed a system of this, however, it still needs a lot of fixes, but used InputBegan and InputEnded.
Since you’re asking about scripting support it would help if you copy/paste your script with 3 backticks (```) before and after it so it formats properly here.
Have you searched any posts or read any of the documentation about debounces?
Depends on how accurate you want the timer to be. I often just use Task.Wait for cooldowns that don’t matter with variability in how long they take. If you want an exact 10s you can use os.clock.
It can look something like this:
local startTime = os.clock()
repeat task.wait() until os.clock() - startTime > 10 -- this will detect exactly when it's been 10 seconds
-- refresh the kill system
That’s the most accurate way to wait 10 seconds but if I was in your scenario I would probably just use a task.wait due to the variability not being a big deal in your situation.