Sadly there isn’t. I’ve thought of any other way of optimizing it but the only thing you could do if you’d like to optimize would be to change “double kick” to a number which would be less readable for you but a bit faster for the system to run if the table has a lot of values.
[EDIT]
Oh wait… you could just check if states.active = true or false.
Your underlying logic is fine and probably won’t get any easier. You could always make a function for it though to break it out of your action handler:
local function Cooldown(name, duration)
cooldowns[name] = true
task.delay(duration, function()
cooldowns[name] = false
end)
end
-- From your task
if inp.KeyCode == Enum.KeyCode.E then
if cooldowns["double kick"] then return end
Cooldown("double kick", 5)
task.wait(1)
states.active = false
end
Of course, that requires you to make sure it’s not set already, or else the function will step on a previously called one.
You could get even fancier and pass a closure function to the cooldown function that only gets called if the cooldown isn’t set:
local function Cooldown(name, duration, callback)
if cooldowns[name] then return end
cooldowns[name] = true
task.delay(duration, function()
cooldowns[name] = false
callback()
end)
end
-- From your task
if inp.KeyCode == Enum.KeyCode.E then
Cooldown("double kick", 5, function()
task.wait(1)
states.active = false
end)
end