Hello there!
I have tried searching at the wiki and forum but I can’t seem to find the answer. Maybe I don’t write the title correctly… But still:
How do I identify what animation is currently playing on a player?
Hello there!
I have tried searching at the wiki and forum but I can’t seem to find the answer. Maybe I don’t write the title correctly… But still:
How do I identify what animation is currently playing on a player?
strong textThere’s a function inside Animators called “GetPlayingAnimationTracks,” which, when called, will return an array of strings.
local Animator = path.to.Animator
local playingAnimations = Animator:GetPlayingAnimationTracks -- Will return an array of strings or, in other words, a table of animations playing in that animator.
local playingAnimation = playingAnimations[1] -- This will get the first animation track in the array of strings.
Do NOT call this function on Humanoids. They deprecated this and suggest that you don’t use this for new work.
Humanoid:GetPlayingAnimationTracks()
Will it identify which animation is playing though? I want a specific animation that is currently being played to detect something.
it wont detect which animation has been played recently, but you can use table.find to find the animation that you want it to detect.
Apologies for the late response!
If you want to find a specific animation inside the table, I’d suggest running a for loop.
local playingAnimations = Animator:GetPlayingAnimationTracks -- The table
local AnimationIdYouAreLookingFor = 123456789 -- Change this to whatever Id you're looking for.
local CorrectAnimationTrack -- Blank variable that will be used in the for loop through the table and check for something like the name or the id. I'd recommend checking for the id because it will be more consistent than names and you want have to change anything if the animation name changes.
for i,track in pairs(playingAnimations) do -- Loop through the table
if track.Animation.AnimationId == AnimationIdYouAreLookingFor then -- Check if the animation inside the animation track has the same id as the one you're looking for
CorrectAnimationTrack = track -- If it is, make the "CorrectAnimationTrack" variable equal that track.
end
end
Not deprecated. Use this.
I was telling the OP to use that. I’m saying don’t use this function on the Humanoids because animation related API in Humanoids is deprecated.