How can I play an animation as soon as 1 ends efficiently

Before you come here and link me a different post solving my answer let me explain

Yes while im aware we can just do:

AnimationTrack.Stopped:Wait() or something like that I see a big issue with this
The issue is that if theres code ahead it will also not run the code until the animation finishes or stops, Yes while im also aware theres events for this too it seems unneficient to hook an event for an action so simple and it would also mess if you are trying to stop it normally.

So if anyone have ideas to get arround this please share them, I tried to find info on this but I couldnt.

You can use a spawn function to play the animation while waiting for the last animation to end. The codes after that will still run regardless if you wait for animation to end with spawn.

I heard you can also use coroutine, but I’m not too experience with it to explain. From the gist I think it runs faster than spawn.

1 Like

You’d handle the animation queuing and playing in its own thread of execution, i.e;

local animationQueue = {anim1, anim2, anim3}

task.spawn(function()
	animationQueue[1]:Play()
	animationQueue[1].Stopped:Wait()
	--Play next animation.
end)

--Code here isn't disrupted.
1 Like

No way! multi threading on lua? So thats why everyone was talking about that task library thing anyways thanks for telling me how to make this!

1 Like

imma take a look at the task library