How do i play animations in an order?

im am currently working on a PVP game and i need help playing animations in an order.

script: if math.random(1,2) == 1 then
PlayingAnimation.Animation:Stop()
PlayingAnimation = Animations.Attack1
PlayingAnimation.Animation:Play()
playSound:FireServer(slashSound)
currentDamage = slashDamage
NormalDamage = true
if not Debugging then
toggleTrail:FireServer(true)
end
Hitbox:HitStart()
Hitted = true
wait(1)
Hitted = false
Hitbox:HitStop()
NormalDamage = false
toggleTrail:FireServer(false)
repeat wait() until (tick() - StartTick) >= PlayingAnimation.Duration
if Equipped then
PlayingAnimation.Animation:Stop()
PlayingAnimation = Animations.Idle
PlayingAnimation.Animation:Play()
end
else
PlayingAnimation.Animation:Stop()
PlayingAnimation = Animations.Attack2
PlayingAnimation.Animation:Play()
playSound:FireServer(slashSound)
currentDamage = slashDamage
if not Debugging then
toggleTrail:FireServer(true)
end
NormalDamage = true
Hitbox:HitStart()
Hitted = true
wait(1)
Hitted = false
Hitbox:HitStop()
NormalDamage = false
toggleTrail:FireServer(false)
repeat wait() until (tick() - StartTick) >= PlayingAnimation.Duration
if Equipped then
PlayingAnimation.Animation:Stop()
PlayingAnimation = Animations.Idle
PlayingAnimation.Animation:Play()
end
end
end
CanUse = true
end
end)

1 Like

you can change animation priorities, if thats not what you meant then you can use task.delay and task.spawn to delay functions and spawn functions.

could you please explain yourself better?
i dont understand , what do you mean? Also be more specific about what part you need help about and what’s the issue

1 Like

like play animation 1 then play animation 2 then 3 ect instead of randomly like 1 2 1 1 1 2 ect.

Have you tried making a table possibly?

You could try something like this (Plays all anims at once in sequence):

local AnimsToPlayInSequence = {
	[1] = nil, --First anim track
	[2] = nil, --Second anim track
	[3] = nil --Third anim track
}


local function PlayAnims(A:{AnimationTrack})
	for _, X in ipairs(A) do
		X:Play()
		X.Ended:Wait()
	end
end

PlayAnims(AnimsToPlayInSequence)

I was about to go dev something when I realized you might just want to cycle through the animations manually. So here:

local AnimsToPlayInSequence = {
	[1] = nil, --First anim track
	[2] = nil, --Second anim track
	[3] = nil --Third anim track
}
local CurrentAnim = AnimsToPlayInSequence[1]

local function PlayAnim()	
	CurrentAnim:Play()
	
	local NextAnim = AnimsToPlayInSequence[table.find(AnimsToPlayInSequence, CurrentAnim)+1]
	
	if NextAnim then
		CurrentAnim = NextAnim
	else	
		CurrentAnim = AnimsToPlayInSequence[1]
	end
end

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