function onKeyPress(actionName, userInputState, InputObject) --KeyPress function
local attackanim = hum:LoadAnimation(Tool.specialattack1) --Load animation
if userInputState == Enum.UserInputState.Begin and cooldown == 0 and swordequipped == 1 then --Conditions to be met
attackanim:Play() --Play animation
cooldown = cooldown + 1 --Activate cooldown
print("Cooldown Added")
elseif cooldown == 1 then
wait(5)
cooldown = 0 --Remove cooldown
print("Cooldown Removed")
end
end
game.ContextActionService:BindAction("KeyPress", onKeyPress, false, Enum.KeyCode.R) --If R key pressed do onKeyPress function
So basically I'm trying to make it so that the special attack animation can only be used every 5 seconds, the cool-down works once but then any subsequent presses allows me to spam the animation indefinitely. Help would be appreciated.

1 comment
Have you tried making “cooldown” equal to one instead of adding to one? It could somehow go over 1 and break the cooldown.