im using task.wait() but for some reason with lower numbers ( like, lets say, 0.05 ) it fires slower than it should ( like if the cooldown was around 0.1 )
Here’s three different cooldown systems you can use:
-- Option 1 (debounce)
local debounce = false
Any.Event:Connect(function()
if debounce then return end
debounce = true
-- code here
task.wait(1)
debounce = false
end)
-- Option 2 (tick)
local lastinput = false
local cooldown = 1
Any.Event:Connect(function()
if not lastinput or tick() - lastinput > cooldown then
lastinput = tick()
-- code here
end
end)
-- Option 3 (deltatime)
local halttime = 0
Any.Event:Connect(function()
if halttime == 0 then
halttime = 1
-- code here
end
end)
game:GetService("RunService").RenderStepped:Connect(function(dt)
halttime = math.max(0, halttime - dt)
end)