All animations stop when trying to stop specific animations?

When a specific part is parented to the player’s character, I call this function in order to stop all the animations below, just in case they’re being played. However, this not only stops these animations, it stops all animations, such as idle, walking, jumping animations and so on. I found out, if I comment out 5 of them, it’ll work as intended. It’s like it’s trying to stop so many animations at once, that it just ends up stopping all animations in the character instead. Is there a more efficient approach to this?

Instead, you could check for all animations whether they are playing.
https://developer.roblox.com/en-us/api-reference/class/AnimationTrack

Especially the bool of IsPlaying. Maybe setting all animation tracks inside a table and looping through it would do?


local function stopAllAnimations()
    for _, animationTrack in next, AnimationsTable do
        if animationTrack.IsPlaying then
            animationTrack:Stop()
        end
    end
end

Follow up the function by playing default animations.

Question: Which animations did you comment in order to make it work as intended?

2 Likes

You can stop all animations this way:

local Humanoid = player.Character.Humanoid
local activeTracksPlaying = Humanoid:GetPlayingAnimationTracks()
for _,v in pairs(activeTracksPlaying) do
    v:Stop()
end
3 Likes

Thank you, after putting all the animationtracks into a table and then calling your function once ChildAdded is fired, it works perfectly.

To answer your question, it actually didn’t matter which animations I had to comment out. If I just randomly commented out 5 of the 9 animations, it would work properly.

When ChildAdded is fired, new animations are being played from the child, which is why I had to stop all the animations from the code above. It works now though, so thank you once again!

One question, is there a more efficient way to do this?

local playPick = Humanoid:LoadAnimation(script:WaitForChild(“Screen”))

local playDive = Humanoid:LoadAnimation(script:WaitForChild(“Dive”))

local playAnkles = Humanoid:LoadAnimation(script:WaitForChild(“Ankles”))
local playArmsUp = Humanoid:LoadAnimation(script:WaitForChild(“ArmsUp”))
local playArmsDown = Humanoid:LoadAnimation(script:WaitForChild(“ArmsDown”))
local playAO = Humanoid:LoadAnimation(script:WaitForChild(“AOAni”))
local playPullUp = Humanoid:LoadAnimation(script:WaitForChild(“PullUp”))
local PlayScreen = Humanoid:LoadAnimation(script:WaitForChild(“Wall”))
local BoxOut = Humanoid:LoadAnimation(script:WaitForChild(“BoxOut”))
local BoxedOut = Humanoid:LoadAnimation(script:WaitForChild(“BoxedOut”))
local Blocking = Humanoid:LoadAnimation(script:WaitForChild(“Blocking”))
local HandsUp = Humanoid:LoadAnimation(script:WaitForChild(“HandsUp”))

– Insert into table

table.insert(AnimationsTable,playDive)
table.insert(AnimationsTable,playAnkles)
table.insert(AnimationsTable,playArmsUp)
table.insert(AnimationsTable,playArmsDown)
table.insert(AnimationsTable,playPick)
table.insert(AnimationsTable,HandsUp)
table.insert(AnimationsTable,BoxedOut)
table.insert(AnimationsTable,playPullUp)
table.insert(AnimationsTable,PlayScreen)

Thank you for your reply. Stopping all of the animations wouldn’t work, since new animations are being played when the child is added, and thus I needed a way to stop specific animations only, and not all animations. Operatik’s answer helped me though. Thank you anyway!

1 Like

https://developer.roblox.com/en-us/api-reference/function/Humanoid/GetPlayingAnimationTracks

I actually checked the page of the function. About the same functionality, however this stops absolutely all animations on the Humanoid. What I believe you are trying to achieve here is to stop certain set of animations only.

1 Like

Yeah exactly. I only needed to stop a certain set of animations, and your reply helped me with my issue, thank you! Would you be able to answer my other question as well? I asked it in another reply to you.

Consider PMing me the question or creating a new topic for it(more favorable in PMs). I’m ready to answer.

1 Like