#Animations continue loading after the cooldown

1 messages · Page 1 of 1 (latest)

austere linden
#

I'm creating a battlegrounds and when I want to reach the fourth animation, which makes the character stand still and can't continue making more animations, the same character can continue playing the animations

austere linden
#

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)´´

harsh cove
#

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)
austere linden
#

so i will put the debounce over here?

#

@harsh cove

harsh cove
#

yeah and get rid of task.delay

#

not necessary for cooldown