How to get currently playing animations?

Hello everyone! I am working on a game that has a feature where when you die, your character doesn’t actually die, you just ragdoll, go lifeless, and then “respawn” at a spawn CFrame a few seconds later, fixed and ready to go.

The only issue is since you don’t actually “die” the Roblox way, when you respawn, if there was an animation playing that either lasted past the respawn or was looped indefinitely like a hold animation, it stays there.

I wanted to find all animation Tracks that are currently playing and end them when you respawn, but the player function humanoid:GetPlayingAnimationTracks() is deprecated, so how would I do this nowadays? Note that the localscript that has the code to respawn is not in the same script as the code that the animations are referenced from and played with.

2 Likes

I bet there is no alternative method to :GetPlayingAnimationTracks(). It is still completely working and I am pretty sure it’s not actually deprecated, but only lacks documentation updates, since we shouldn’t be loading animations to humanoid anymore, but to animator instead, because stability is ensured that way.

One “hacky” way would involve loading a new blank animation, but that would be a waste of time and resources, since :GetPlaingAnimationTracks() fulfills that purpose and enables you to manage all playing tracks more efficiently.

EDIT
@Y35X I’m glad that I could help. I was confused too at first, because it was only said that humanoid:LoadAnimation() is deprecated and all the other related animation methods with it. There used to be an issue with loading/replicated Animator from the server, which is an object that manages animations further.

Here is the original announcement article: Deprecating LoadAnimation on Humanoid and AnimationController
And here is Animator API (:GetPlayingAnimationTracks() is one of it’s functions listed): Animator | Roblox Creator Documentation

-- Animator is direct child of humanoid.
animator:GetPlayingAnimationTracks()
11 Likes

Oh wow, I wasn’t even aware of the “animator” child of humanoid, I need to look more into that.

What you said worked though, it still is a function that works, so thanks!

1 Like

Just to be clear, Humanoid:GetPlayingAnimationTracks() is only deprecated in favor of calling the same method on an Animator. Essentially it has just “moved”.

Animator:GetPlayingAnimationTracks (roblox.com)

2 Likes