Implementing Ability Cooldowns

I currently have a system that uses CAS(Context Action Service) and implementing a way to create and manage cooldowns has been a problem. The issue is, whenever i try and use a solution (Coroutine, RemoteEvents, tick(), os.time, IntVals), they usually turn out to just yield the entire script + make every ability wait until the cooldown is finished before you can use another move.

The question i have is, what would be the best performance cooldown system that has worked for you? Or what solutions could you reccommend? :sleepy:

Hello. Ive had your problem when making tool cooldowns for a game I am working on.
Even if it says you have used Coroutine, have you used it like this?

coroutine.wrap(function()
	task.wait(cooldown)
	-- code here
end)()

This seems to have worked for me everytime I use it.
However, if the problem still persists, I may not be able to help you.

1 Like

Yes i belive i have, although, i did not add the brackets like you, i will try it out and let you know.

Yea, this incurs the problem described above.

While it will inplement the cooldown for the ability, all abilities have to wait for it to finish before they can run.

Thank you for your help though :face_exhaling:

		local function EEvent(ActionName, InputState, _InputObject)
	if ActionName == Action_E and InputState == Enum.UserInputState.Begin and CartonEvent and Activated == true then
		local Char = Player.Character or Player.CharacterAdded:Wait()
		Activated = false
		print("Carpet bomb incoming")
		for i = 0, 5, 1 do
			local RanNum = math.random(1,5)
			local MPOS = Mouse.Hit.Position
			CartonEvent:FireServer(Char.HumanoidRootPart.Position, MPOS, RanNum, 150)
			wait(.2)
		end
		coroutine.wrap(function()
			task.wait(1)
			Activated = true
		end)()
	else
		warn("Can only run one at a time")
	end
end

Cant you just add the coroutine.wrap() before the for i, 0, 5, 1 do if that happens? (or is that not what youre looking for)

I’m not exactly sure what you mean by that, could you elaborate?

Although i’m thinking adding a coroutine before it would just cause it to delay before execution. Right?

i believe the main issue here is because your function is a single function, if you active it, you will need to wait for it to finish

local function Attack(Method, range, force)

-- the problem is ,when you start this, you will need to wait it to finish

end

your best shot is doing something like this:

coroutine.wrap(EEvent)(ActionName, InputState, _InputObject) << after you press G, for example, you will start this function without colliding with the same function if you start it once again
(correct me if i'm wrong)




you could store different functions for each ability inside a table, and when you use an specific ability it will activate on the Table according to its name

like this:


local List_Of_Skills = {

["Thunder"] = function(Method, range, force)

end,

["Fire"] = function(Method, range, force)

end,


}

coroutine.wrap(List_Of_Skills[Skill_Name]()

Skill_Name must be a String, but this is a mere reference, look above

local Skill_Name = "Thunder" -- your current ability for example

isnt the point of coroutine.wrap() to run while your other code is running? I dont think it would delay if you use the coroutine correctly. Also, what i mean is this

		local function EEvent(ActionName, InputState, _InputObject)
	if ActionName == Action_E and InputState == Enum.UserInputState.Begin and CartonEvent and Activated == true then
		local Char = Player.Character or Player.CharacterAdded:Wait()
		Activated = false
		print("Carpet bomb incoming")
		coroutine.wrap(function()
			task.wait(1)
			Activated = true
		end)()
		for i = 0, 5, 1 do
			local RanNum = math.random(1,5)
			local MPOS = Mouse.Hit.Position
			CartonEvent:FireServer(Char.HumanoidRootPart.Position, MPOS, RanNum, 150)
			wait(.2)
		end
	else
		warn("Can only run one at a time")
	end
end

Yea, i’ve already tried that and got the same issue. :confused: Thank you though.

Alright, great idea. I’ll try it and let you know the results.

1 Like