How would I handle cooldowns for Skills, or combos?

I’ve been making a combat system, I handle animation and hitbox on Client side and damage and effects (Poison, Paralyzed, etc…). I have problem with the cooldown stuff… which makes me scrapped a lot of code or the entire script or project itself. So I need tips and steps to learn about cooldowns and stuff for skills and combos.

If you’re gonna make combat systems then you’re gonna have to manage multiple cool-downs. You can manage these with a table, which will keep track of what abilities you have used and are in cool-down. I would recommend having a configuration of cooldown values in RepStorage since different abilities have different cool-downs

local cooldowns = {}
Ability.Used:Connect(function(ability) — Change this connection to whatever you will detect when you use the ability 
   if tick() - (cooldowns[ability]) <= game.ReplicatedStorage.CooldownConfigurations[ability].Value then
      print(“Unable to use ability, in cooldown”)
      return
   else
     — Run your ability 
     cooldowns[ability] = tick()
end)

This is the code we need to see if the player’s ability is in cooldown or not. If it isn’t then we add their ability to the cooldowns table. If it is then we warn them that they can’t use it
With this, you should be able to make a functional cooldown system :slight_smile:

1 Like

cool this looks great, but is it efficient? :face_with_raised_eyebrow: Just asking

The performance of this depends on the number of abilities you’ve got. If you want to, you can change the while wait() to a while wait(1) if that bothers you. Otherwise, this is simplest way to manage the cooldowns of a bunch of abilities in your combat system

So its also great with combos?
If so then this is great :laughing:

Yeah I guess, since it manages every ability

is there an error here? I suppose your supposed to take the current tick - the last fire tick and check if it is larger than cooldown? Correct me if I am wrong

You don’t need to do that. I’ll give you an example.
Let’s say you activated an ability. It’s not in the cooldowns list so it will be allowed to take place and then it’ll be added to the list. If you activate it while it’s still in the list (ie. it’s in cooldown), then it won’t take place

You could just store the time of the last usage/hit. When the move is used again, subtract the current time minus the time of the last usage and check if enough time has passed for the cooldown. I think it would be much more efficient than @MysteryX2076 's solution

1 Like

Hmm that’s actually a very good idea, thanks for your improvement! (Im bad at optimisation since I tend to overthink)

Edit: Improved it now