Creating an Attack Cooldown

  1. What do you want to achieve? Keep it simple and clear!

I’m trying to create an enemy AI script, but I’m struggling to create a cooldown for the attack.

attack script

I’ve tried to use the wait() function but it also pauses the AI movement.

Thanks!, Shiva

You can use collectionservice.

if not game:GetService("CollectionService"):HasTag(base, "AttackCD") then
	game:GetService("CollectionService"):AddTag(base, "AttackCD")
	task.delay(2,function() -- replace 2 with your with cooldown timer.
		game:GetService("CollectionService"):RemoveTag(base, "AttackCD")
	end)
	player.Humanoid:TakeDamage(damage)
end

Holy cow it worked! I really need to learn more about coding, thanks!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.