So I’ve made a combat system with combos:
--// Animation functions
local function AttackOne()
coroutine.wrap(function()
AttackTrack1 = script.Parent.Parent.Humanoid:LoadAnimation(Attack1)
AttackTrack1.Priority = Enum.AnimationPriority.Action
AttackTrack1:Play()
end)()
end
local function AttackTwo()
coroutine.wrap(function()
AttackTrack2 = script.Parent.Parent.Humanoid:LoadAnimation(Attack2)
AttackTrack2.Priority = Enum.AnimationPriority.Action
AttackTrack2:Play()
end)()
end
local function AttackThree()
coroutine.wrap(function()
AttackTrack3 = script.Parent.Parent.Humanoid:LoadAnimation(Attack3)
AttackTrack3.Priority = Enum.AnimationPriority.Action
AttackTrack3:Play()
end)()
end
local function AttackFour()
coroutine.wrap(function()
AttackTrack4 = script.Parent.Parent.Humanoid:LoadAnimation(Attack4)
AttackTrack4.Priority = Enum.AnimationPriority.Action
AttackTrack4:Play()
end)()
end
local function AnimationOrder()
if streak == 0 then
AttackOne()
elseif streak == 1 then
AttackTwo()
elseif streak == 2 then
AttackThree()
elseif streak == 3 then
AttackFour()
end
end
local function AnimationEnded()
if streak == 1 then
AttackTrack2.Stopped:Wait()
AnimationCool = false
print("Streak 1 Passed")
elseif streak == 2 then
AttackTrack2.Stopped:Wait()
AnimationCool = false
print("Streak 2 Passed")
elseif streak == 3 then
AttackTrack3.Stopped:Wait()
AnimationCool = false
print("Streak 3 Passed")
elseif streak == 4 then
AnimationCool = false
print("Streak 4 Passed")
elseif streak == 0 then
AnimationCool = false
print("Streak 0 Passed")
end
end
--// Combo System
tool.Activated:Connect(function()
if ComboCool == true then return end
if AnimationCool == true then return end
AnimationCool = true
if tick() - PreviousPunch <= 2 then -- If previous punch was operated in 0.5 seconds,
if streak >= 4 then -- If streak was continued for 3 times,
streak = 0 -- change streak to 0.
ComboCool = true
wait(1)
ComboCool = false
end
streak = streak + 1
print(streak)
else -- If time from last punching operation was over than 0.5 seconds,
streak = 0 -- reset your streak.
end
PreviousPunch = tick()
AnimationOrder()
AnimationEnded()
local EnemyChar = FindPlayer()
if EnemyChar ~= nil then
game.ReplicatedStorage.Remotes.TakeDamage:FireServer()
end
end)
And I want the cooldown between each animation to be the animation’s length
Problem is, AnimationEnded() stops working at “Streak 1 Passed” print and “2” streak print.
Thank you for reading