How to change active animations

Hello, I’m trying to make a system where I either equip a tool or more importantly press a key and it’ll change lets say my idle or my walk, ect. How could I change animations and then be able to change them back at will? Is there a way to find lets say all animation tracks being run by the humanoid and then updating them to certain id’s or would I need some finesse?

Any and all help means the world to me, I’m a solo dev trying to learn every form of development and scripting has been my achilles heel but I’m still progressing.

I believe you can play an animation at a time. So putting Animation:Play() should just stop the animation played before and play the one you are telling to play.
This maybe wrong as I don’t have much experience with animations.

1 Like

I’ve tried switching animations before and they just play over each other and look weird, I’m basically trying to swap the characters idle and keeping it that way, but not sure how.

I would recommend loading the animation using Humanoid:LoadAnimation() at the start of a local script inside of the tool. Then using an event for when the tool is equipped, use Animation:Play() on the LoadAnimation() function to play the animation. Similarly, you can also use Animation:Stop() on the LoadAnimation() when the tool is unequipped to stop the animation.

If the animation does not loop, make sure you set it looped when creating the animation in the animation editor and setting the animation priority to idle may also help.

1 Like

Thing is if I’m not mistaken, that method would fuse animations and play both animations at half, cause lets say jump animations or fall animations, how would that animation system recognize any of that, would that animation just keep playing, like lets say a run animation would just keep playing when I run, or would I have ot go so far as to detecting humanoid state and change the animation based on that? Wish there was a simpler way of changing animations.

If it’s the simple movement animations that you would like to replace then just duplicate the local “Animate” script inside of the player’s character and paste it into the StarterPlayer > StarterCharacterScripts. Afterward, just find the right Animation instance under the “Animate” script and change the AnimationId.

2 Likes

There is no function that will return you all the loaded animation tracks but there is a function that gets the current playing ones using Humanoid.Animator:GetPlayingAnimationTracks()

1 Like

I tried that and it’d play the animations at half, unless I did it wrong. You’re suggesting basically having 2 animate scripts within the character right?

This will help you to stop all playing animation, a solution similar to your problem : https://devforum.roblox.com/t/how-to-stop-all-player-animations/1098890/2?u=milkyfiend

1 Like

so could I basically stop all humanoid animations, replace the animate script animationID’s and then it’ll run those new animations for me?

After reading the solution that what It would do. I mean when we play animations they are inside of player character, aren’t they? Try it with a new script.

1 Like

And This is what you are looking for…
Stop all playing animations for a certain player (the same code from the documentation :

local animator = humanoid:WaitForChild("Animator")

-- Stop all animation tracks
for _, playingTrack in animator:GetPlayingAnimationTracks() do
	playingTrack:Stop(0)
end
2 Likes

So I imagine I’d stop the animations and then just replace the id’s of the Animate script? sorry I’m not good when it comes to switching animations.

well yeah. Depends on what you want. Like if you want to stop a certain animation then you might just want to stop that one… Do some testing

1 Like

I mainly want to do something like replace all animations in general, I’ll 100% test it out though, thank you again

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.