#Animations continue loading after the cooldown
1 messages · Page 1 of 1 (latest)
lua ´´local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local ClickAttack = ReplicatedStorage.Events:WaitForChild("ClickAttack")
local AttackAnimations = ReplicatedStorage:WaitForChild("AttackAnimations"):GetChildren()
local Cooldowntime = 1.5
local COOLDOWN_BETWEEN_ATTACKS = 0.5
local AttackCooldown = {}
local PlayerCombos = {}
local ActiveAnimations = {}
local M1Cooldown = {}
ClickAttack.OnServerEvent:Connect(function(player)
local Personaje = player.Character
if not Personaje then return end
local humanoid = Personaje:FindFirstChild("Humanoid")
local animator = humanoid and humanoid:FindFirstChild("Animator")
if not humanoid or not animator then return end
if PlayerCombos[player] == 5 then
return
end
if M1Cooldown[player] then
return
end
if not PlayerCombos[player] then
PlayerCombos[player] = 1
end
if ActiveAnimations[player] then
ActiveAnimations[player]:Stop()
end
local animationIndex = PlayerCombos[player]
local animation = AttackAnimations[animationIndex]
if not animation then return end
local animationTrack = animator:LoadAnimation(animation)
ActiveAnimations[player] = animationTrack
animationTrack:Play()
PlayerCombos[player] = PlayerCombos[player] + 1
M1Cooldown[player] = true
task.delay(COOLDOWN_BETWEEN_ATTACKS, function()
M1Cooldown[player] = nil
end)
if PlayerCombos[player] == 4 then
humanoid.WalkSpeed = 0
humanoid.JumpHeight = 0
task.delay(Cooldowntime, function()
humanoid.WalkSpeed = 16
humanoid.JumpHeight = 7
PlayerCombos[player] = 1
ActiveAnimations[player] = nil
end)
end
end)´´
why are you using task.delay() for the cooldown just use a debounce my man
which looks like this:
local debounce = false
ClickAttack.OnServerEvent:Connect(function(player)
if debounce then return end
-- code here
debounce = true
task.wait(cooldown)
debounce = false
end)