Serious animation problem

I just want to change the walk animation and the idle animation of players whenever I want to. The problem is: due to a flaw in the roblox animating script, the animations won’t play if the previous animation is in use.

for example, if I change the walking animation, then the new animation won’t play while I am still walking. You would have to stop walking and then start walking again for it to play.

This is a serious issue in my game, because I have tons of animations and I have to do weird tricks that are probably bad practice in order to get the animations to play properly. For example, I usually put my teleport parts high in the air so the falling animation will play before the idle animation. I also force the character to stop moving and walk again.

Here is how I change the animations:

hit.Parent.Animate.walk.WalkAnim.AnimationId = "rbxassetid://8137104876"
hit.Parent.Animate.idle.Animation1.AnimationId = "rbxassetid://8137256167"
hit.Parent.Animate.idle.Animation2.AnimationId = "rbxassetid://8137256167"

It works fine because of my weird methods to make it work properly, but due to lag it sometimes doesn’t work, and you might end up crawling around the map when you’re not suppose to.

Please help me, because so far this is still the number 1 issue in my game.

1 Like

You’ll have to load the walking animation on the Animator then :Stop() and :Play() it again. If your script changes the walking animation, this is the only way I can see you achieving this.

Do you mean AnimationTrack:Play()

I did try that, but then the animation just keeps playing forever regardless of how you control your character

Sorry my bad. Also it doesn’t matter, audios and Animations both use :Stop() and :Play() so I don’t have to reference it in specific. Thanks though.

What I meant to say was try loading the previous animation using :LoadAnimation, stopping the animation, then changing it to the new animation. Load the new animation, but don’t play it. Since Roblox’s script handles the animation priorities, this should work. If this doesn’t end up working, you’ll have to write your own due to limitations with Roblox’s.

1 Like

That didn’t seem to work for me

if hit.Parent:FindFirstChild("Humanoid") ~= nil and debounce == 0 then
			debounce = 1
			local walkAnimationTrack = hit.Parent:FindFirstChild("Humanoid"):LoadAnimation(hit.Parent.Animate.walk.WalkAnim)
			walkAnimationTrack:Stop()
			hit.Parent.Humanoid.WalkSpeed = 5
			hit.Parent.Animate.walk.WalkAnim.AnimationId = "rbxassetid://8137104876"
			hit.Parent.Animate.idle.Animation1.AnimationId = "rbxassetid://8137256167"
			hit.Parent.Animate.idle.Animation2.AnimationId = "rbxassetid://8137256167"
			hit.Parent.Humanoid.JumpPower = 0
			wait(2)
			debounce = 0

Could you please show me an example of how you would do that?

One thing I need to get straight first:

When you change the animation, what animation type do you have your animation set to? If it’s anything but Core, that explains why it just looped the walking animation. Also does it only work if you stop walking and start walking again?

I will do some personal investigation. As I said earlier, this might be due to the way Roblox has their script setup. I don’t do walking animations often, so I wouldn’t be able to help until I tried it myself

1 Like

All of my animation priority is set to action

have you tried to stop all animations and animationtracks of the player before changing their animations? maybe try to reload the character after changing their animations?

Oh my gosh. I can’t believe I finally figured it out. Turns out that setting the animation priority to action was the problem. Thank you so much!

There’s just one problem left though. When I use AnimationTrack:Play() then the animation will play on my character no matter what (it could play the walking animation while I am idle.) Is there a way to fix this?

I tried detecting if the player is walking or not. Is this the correct way I should do it?

			if hit.Parent:FindFirstChild("Humanoid").MoveDirection == Vector3.new(0,0,0) then
				local AnimationTrack = hit.Parent:FindFirstChild("Humanoid"):LoadAnimation(hit.Parent.Animate.idle.Animation1)
				AnimationTrack:Play()
			else
				local AnimationTrack = hit.Parent:FindFirstChild("Humanoid"):LoadAnimation(hit.Parent.Animate.walk.WalkAnim)
				AnimationTrack:Play()
			end

I use a similar method for my Sprint script.

You could probably learn something from this:

repeat
						task.wait()

						-- Check if Sprint is already being played
						if IsSprinting == true then
							-- do nothing
						else
							IsSprinting = true
							LoadedSprintAnim:Play()
						end

						-- Check if the player is even moving
						if Humanoid.MoveDirection == Vector3.new(0, 0, 0) then
							Humanoid.WalkSpeed = OriginalWalkSpeed
							Humanoid.JumpPower = OriginalJumpPower

							LoadedSprintAnim:Stop()
							IsSprinting = false
						elseif Humanoid:GetState() == Enum.HumanoidStateType.Jumping or Humanoid:GetState() == Enum.HumanoidStateType.Freefall or Humanoid:GetState() == Enum.HumanoidStateType.None or Humanoid:GetState() == Enum.HumanoidStateType.Seated then
							Humanoid.WalkSpeed = OriginalWalkSpeed
							Humanoid.JumpPower = OriginalJumpPower

							LoadedSprintAnim:Stop()
							IsSprinting = false
						end

						-- Check if the LeftShift is no longer being held
						if LoopShouldEnd == true then
							LoadedSprintAnim:Stop()
							
							Humanoid.WalkSpeed = OriginalWalkSpeed
							Humanoid.JumpPower = OriginalJumpPower
							
							IsSprinting = false
							break
						end

						-- Run until one of these parameters are met
					until Humanoid.MoveDirection == Vector3.new(0, 0, 0) or Humanoid:GetState() == Enum.HumanoidStateType.Jumping or Humanoid:GetState() == Enum.HumanoidStateType.Freefall or Humanoid:GetState() == Enum.HumanoidStateType.Seated

It’s not my full script, just a section of it you might need reference for.

Update on this:

There is a community resource on the issue!