Change players run animation while moving?

Basically in the game when the player stats sprinting I change their running animation. But this doesn’t actually apply until I stop moving and start moving again. I have tried to stop all the active animations in the player after applying the new animation ID in hopes that it would force it to restart with the new one but it seems to do nothing. Here is the code which is in a server script(tried disabling anims locally too) that is in the player character:

local MS = script.Parent.CharInfo.MoveState
local WS = script.Parent.CharInfo.WeaponState
local WT = script.Parent.CharInfo.WeaponType
local Chr = script.Parent
local animateScript = Chr:WaitForChild("Animate")

MS.Changed:Connect(function() --MoveState Changed
local AnimationTracks = Chr.Humanoid:GetPlayingAnimationTracks()

for i, v in pairs (AnimationTracks) do
if MS.Value == "Walk" then --Player Walking
	if WS.Value == "Armed" then --Player Armed
		if WT.Value == "Rifle" then --Armed Rifle = "rbxassetid://4169434554"
			animateScript.walk.WalkAnim.AnimationId = "rbxassetid://4169434554"
		elseif WT.Value == "Pistol" then --Armed Pistol
	elseif WS.Value == "UnArmed" then --PLayer unarmed
elseif MS.Value == "Sprint" then --Player Sprinting
	if WS.Value == "Armed" then --Player Armed
		if WT.Value == "Rifle" then --Armed Rifle = "rbxassetid://4169584019"
			animateScript.walk.WalkAnim.AnimationId = "rbxassetid://4169584019"
		elseif WT.Value == "Pistol" then --Armed Pistol
	elseif WS.Value == "UnArmed" then --Player Unarmed

Sorry seems like a stupid problem but I can’t seem to get around it. I have looked through tons of forums and the GetPLayingAnimationTracks() seems to be the solution but it does nothing for me doesn’t even stop the running animation.


Have you changed the animation priority of the Sprint and Walking? Another thing is that how are the variables changing, are you using UIS or something else?

In addition, I’d also suggest using an Animation Instance, loading that into the player, and then playing it to see if it helps.


I know this is an old post, but I ran across it after experiencing the exact same problem: I am trying to change the ‘run’ animation, mid-run, but found that the animation will only change if the player stops running, even for a split second.

I’m new to all of this, so my solutions are generally very low tech. I ended up handling this by forcing a very short pause in the running by setting the walk speed to zero and back quickly. It does produce the slightest of stutters, but works well to force the animation change mid-run.

I have these few lines within my larger functioned triggered when I want the animation(s) changed: = ("rbxassetid://04827147149")
		character.Animate.walk.WalkAnim.AnimationId = ("rbxassetid://04827121322")
		humanoid.WalkSpeed = 0
		humanoid.WalkSpeed = player.Speed.Value
1 Like

Sadly, changing animation ID’s to swap between walking - running animations is impossible and requires hacky workarounds (like you provided). You have to load a custom animation into the humanoid and play it whenever the player starts running to do it properly.
The issue is that you need to make a lot of logistic checks for character running, jumping, being blocked, etc. to make sure that the running animation is fluid - playing, stopping and replaying the animation at specific times and events.

So if you’re looking for a simple run animation, just do
local Animation = Humanoid:LoadAnimation(RunningAnimation)
whenever you want to run, and
to stop the running animation. I’ll leave the logistics up to you.


Elaborating on this, Humanoid:GetPropertyChangedSignal(“MoveDirection”) is a great event to use when determining if the player is running or not, Humanoid.MoveDirection is a Vector3 that shows you the direction relative to the world (with magnitude of 1 when moving, and 0 when not) which means if it’s anything but,0,0) then the player is moving/running. if you have sprinting you can do Root.Velocity or WalkSpeed checks as well. finally for ground checking humanoid.FloorMaterial can be used, anything other than Enum.Material.Air means you’re on the ground.


I ran into this issue as well and found a pretty simple solution:

  1. Play the new animation manually. (The current animation will continue playing “underneath” the new one)

  2. Listen for the Stopped event on the current animation track.

  3. Stop the new track when that event fires.

     for _, currTrack in pairs(humanoid:GetPlayingAnimationTracks()) do
         if currTrack.Name == "RunAnim" then
             print("is running")
             local newAnim ="Animation")
             newAnim.AnimationId = ANIM_SWORD_RUN
             local newTrack = humanoid:LoadAnimation(newAnim)
             newTrack.Looped = true
                 print("stopped running")

This way you don’t have to look at WalkSpeed, MoveDirection, FloorMaterial, or anything of that sort to determine when the new animation should stop.


Just a late suggestion, It would work perfectly if you could somehow fuse your script with the default animate script, found in the player. this would make playing animations and switching them out really smooth, Sadly I don’t know how to do that YET. And will be experimenting with this in the future -.-

1 Like

Here’s one possible solution.
I’ve used this too and it works fine as long as humanoid’s walk speed changes when you toggle between run and walk.

Hi, the thread is from 2019, remember to check the date :smiley:

You could try playing both animations and simply changing the animation speed when you change stat. For instance when walking, walkinganim:AdjustSpeed(1). Then for when sprinting is true do walkinganim:AdjustSpeed(0), sprintanim:AdjustSpeed(1).