So I’m working on a combo system for my game, but I’m noticing that there’s weird behavior where the animations for the punches will either have a small delay before the next punch or they’ll play faster than they’re supposed to and I’m not sure how to fix it, I’ve tried preloading the animations using ContentProvider on a local script but that doesn’t really seem to fix the issue.
Here’s my code, what could be the issue?
local lastm1 = 0
local cd = false
local animations = script.Parent.Animations
script.Parent.M1.OnServerEvent:Connect(function(player)
local character = player.Character
local humanoid = player.Character:FindFirstChild("Humanoid")
local sound = script.Parent.Swing:Clone()
sound.Parent = character
if cd == true then return end
cd = true
if tick() - lastm1 > 1 then
count = 1
end
spawn(function()
count = count + 1
end)
lastm1 = tick()
if count == 1 then
local punch1 = humanoid:LoadAnimation(animations.Punch1)
punch1:Play()
sound:Play()
task.wait(.4)
cd = false
elseif count == 2 then
local punch2 = humanoid:LoadAnimation(animations.Punch2)
punch2:Play()
sound:Play()
task.wait(.4)
cd = false
elseif count == 3 then
local punch3 = humanoid:LoadAnimation(animations.Punch1)
punch3:Play()
sound:Play()
task.wait(.4)
cd = false
elseif count == 4 then
local punchKB = humanoid:LoadAnimation(animations.PunchKB)
punchKB:Play()
sound:Play()
task.wait(1)
cd = false
if count == 4 then
count = 1
end
end
end)```