Help with running animation not updating!

So I made a script that changes your running animation, but then if you update the animation it wont change until you stop running and run again, please help.

1 Like

Can you give more context to this by showing your script or something?

local c = script.Parent
local h = c:WaitForChild("Humanoid")
local animate = c:WaitForChild("Animate")


while wait() do
	
	if game.ReplicatedStorage.PlayerValues.MomentumState.Value == 1 then
		animate.walk.WalkAnim.AnimationId = game.ReplicatedStorage.PlayerAnimation.LightRun.AnimationId
		h.WalkSpeed = 8
		end
	if game.ReplicatedStorage.PlayerValues.MomentumState.Value == 3 then
		h.WalkSpeed = 30

		animate.walk.WalkAnim.AnimationId = game.ReplicatedStorage.PlayerAnimation.HRun.AnimationId
		end
	if game.ReplicatedStorage.PlayerValues.MomentumState.Value == 2 then
		animate.walk.WalkAnim.AnimationId = game.ReplicatedStorage.PlayerAnimation.LightRun.AnimationId
		h.WalkSpeed = 20
		end
	
	if h.MoveDirection == Vector3.new(0,0,0) and game.ReplicatedStorage.PlayerValues.Crouching.Value ~= true then
		game.ReplicatedStorage.PlayerValues.MomentumState.Value = 2
		animate.walk.WalkAnim.AnimationId = game.ReplicatedStorage.PlayerAnimation.LightRun.AnimationId
	end
	
	if h.WalkSpeed == 20 then
		game.ReplicatedStorage.PlayerValues.MomentumState.Value = 2
		animate.walk.WalkAnim.AnimationId = game.ReplicatedStorage.PlayerAnimation.LightRun.AnimationId
	end
	
	
	end

Here.

1 Like

Why not just play different animation instances and stop the old one?

I mean, I’m not sure, but I wanna stick to one thing, is there anyway I can update the walking animation?

1 Like

Maybe try stopping and replaying the same instance when you update the ID? I don’t really know cause I’ve never tested it out, but another question: Is the walkspeed changing or is the just the anim that’s not?

Oh, It’s just the animation that isn’t updating.
{Characterss}

1 Like

Then you should probably do what I said, use play a different anim instance and stop the old one. I also recommend to use :GetPropertyChangedSignal instead of while wait() do.

More info here: Instance | Roblox Creator Documentation

1 Like

Okay, I’m going to try that.
Thanks.

1 Like

Alright tell me if you have anymore problems with it.

1 Like

So slight problem, because of the loop the animation freezes.

1 Like

What you could probably do is check if the animation is already being played or not. If it is, then return.

Sorta like this:

 if Animation.IsPlaying then
      return
elseif not Animation.IsPlaying then
     Animation:Play()
     h.WalkSpeed = WalkSpeed
end
1 Like

Wow, I never knew about “IsPlaying” Lemme test it out, Thanks!

1 Like