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
v:Stop()
end
if MS.Value == "Walk" then --Player Walking
if WS.Value == "Armed" then --Player Armed
if WT.Value == "Rifle" then --Armed Rifle
animateScript.run.RunAnim.AnimationId = "rbxassetid://4169434554"
animateScript.walk.WalkAnim.AnimationId = "rbxassetid://4169434554"
elseif WT.Value == "Pistol" then --Armed Pistol
end
elseif WS.Value == "UnArmed" then --PLayer unarmed
end
elseif MS.Value == "Sprint" then --Player Sprinting
if WS.Value == "Armed" then --Player Armed
if WT.Value == "Rifle" then --Armed Rifle
animateScript.run.RunAnim.AnimationId = "rbxassetid://4169584019"
animateScript.walk.WalkAnim.AnimationId = "rbxassetid://4169584019"
elseif WT.Value == "Pistol" then --Armed Pistol
end
elseif WS.Value == "UnArmed" then --Player Unarmed
end
end
end)
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:
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)
then Animation:Play()
whenever you want to run, and Animation:Stop()
to stop the running animation. I’ll leave the logistics up to you.
I ran into this issue as well and found a pretty simple solution:
Play the new animation manually. (The current animation will continue playing “underneath” the new one)
Listen for the Stopped event on the current animation track.
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 = Instance.new("Animation")
newAnim.AnimationId = ANIM_SWORD_RUN
local newTrack = humanoid:LoadAnimation(newAnim)
newTrack.Looped = true
newTrack:Play()
currTrack.Stopped:Connect(function()
print("stopped running")
newTrack:Stop()
end)
end
end
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 -.-
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).