How to add Cooldown?

Hello :smiley: Thanks for clicking on this post.
I just wanted to ask if someone knows how to add a Cooldown to this Script.
If yes would be very cool if you could tell it me :3 anyways have a great day.

Can’t you just use a debounce for the cooldown?

add this variable:

local cooldown = false

update your function:

if cooldown == false then
cooldown = true
--the code in your function
wait(0.5) --change to how much time you want the cooldown to take
cooldown = false
end
3 Likes
local Debounce = false
function onKeyPressed(inputObject, gameProcessEvent)
     if Debounce == true then
      print"Already Pressed"
     return
end
Debounce = true -- activate it, so u won't spam it

    if inputObject.KeyCode == Enum.KeyCode.H then
    humanoid:LoadAnimation(anim):Play()
    print("Animation is playing")
    wait(0.5) -- your time /Cool down here
    Debounce = false
    end

--  Debounce = false -- you can place here too
end
uis.InputBegan:Connect(onKeyPressed)
4 Likes

Here is a script for multiples cooldowns

local amount = 5
local cooldowns = {
    ["name of cooldown"] = false;
-- you can clone ["name of cooldown"] = false; to do more
}
local function run()
       -- code here
end
if cooldowns["name of cooldown"] == false then
      cooldowns["name of cooldown"] = true
      run() --- runs the function with the code
      task.wait(amount) -- task.wait() its better for my opinion
      cooldowns["name of cooldown"] = false
end
--[[
To do more cooldowns copy
if cooldowns["name of cooldown"] == false then
    cooldowns["name of cooldown"] = true
    run() --- runs the function with the code
      task.wait(amount)
     cooldowns["name of cooldown"] = false
end
and change ["name of cooldown"] to the other cooldown.

]]

I hope this helps :slight_smile:

1 Like