Hey there! I have been trying to create a BAE Command Cooldown basically it stops the user from executing commands too quick. I have looked on the hub and didnt find any.
debounce = false
function code()
if debounce == true then return end
debounce == true
-- if your code yields then you can task.spawn()
task.spawn(function()
wait(3)
debounce = false
end)
-- otherwise you can just do your code and wait after
-- (code)
wait(3)
debounce = false
end
The debounce method @Exozorcus mentioned is the most common way to do a cooldown. However, I prefer using tick()
or os.clock()
like this:
local last = tick()
local cooldown = 2 -- seconds
local function Code()
if tick() - last < cooldown then return end
last = tick()
-- code
end
I find this shorter to write since the cooldown code in the function is only 2 lines and doesn’t visually interrupt the code inside unlike the debounce method.
1 Like
This method is way better than a boolean change, as you can read the time left as well directly from a tick()
so you can display that in debug or general player use
2 Likes
Alright… let me try this. One moment.
Im new to scripting, and for Basic Admin. How would i detect when a command is run, like the original command then i would run the code?