Wait for animation to finish, then play the next

As you can see, the animate function will instantly play the next animation. How would I stop the second function from being called until the first animation function finishes.

function module:EquipAnim()
	Animate("rbxassetid://8911061148", false)
	Animate("rbxassetid://8900324101", true)
end

function Animate(animationID, looped)
	local animation = Instance.new("Animation")
	animation.AnimationId = animationID
	
	local animator = self.ViewModel.Humanoid:FindFirstChildOfClass("Animator")
	local AnimationTrack = animator:LoadAnimation(animation)
	AnimationTrack.Looped = looped
	AnimationTrack:Play()
end
1 Like

https://developer.roblox.com/en-us/api-reference/event/AnimationTrack/Stopped

Use this in conjuction with

Event:Wait() since it will yield the script

1 Like

Do you mean AnimationTrack.Stopped:Wait()?
If so, the first animation still seems to get cut off by the second one.

Yes so something like that above

function Animate(animationID, looped)
	local animation = Instance.new("Animation")
	animation.AnimationId = animationID
	
	local animator = self.ViewModel.Humanoid:FindFirstChildOfClass("Animator")
	local AnimationTrack = animator:LoadAnimation(animation)
	AnimationTrack.Looped = looped
	AnimationTrack:Play()
    AnimationTrack.Stopped:Wait()
end

Yep, it works fine, my initial problem with the animation being cut off was simply because of an animation error.
But there’s this moment when the second animation is being played and it seems to bug out?
https://gyazo.com/09933f19d44d17f4d62f768b6801a180

1 Like

so do you want the animation to play like ASAP right after the first one?

I want to stop that weird reversing the animation seems to do when trasitioning. If playing it instantly solves it then yeah.

1 Like

I’d say load the animation into the humanoid at the start of the script before any other function like Equip is allowed to run. That way when you run that function, it doesn’t take time to load it up via id and you can run it instantly (basically preloaded)

Using PreloadAsync, the problem still seems to persist.
I suppose I’ll have to individually play out the animations, but this seems like a really hacky way of doing it.

you dont need to use preloadasync, i mean load it into the humanoid near the top of the script or inside some sort of init function