How do I override the walking animation to play a different animation while sprinting?

I’ve modified the basic animation script to use my animations. I also implemented code to make you sprint. While it does make me move faster, the run animation I specified does not play. I am not too great with animations, does anyone know a solution?

function onRunning(speed)
	if speed > 0.01 then
		playAnimation("walk", 0.1, Humanoid)
		if currentAnimInstance and currentAnimInstance.AnimationId == "http://www.roblox.com/asset/?id=180426354" then
			setAnimationSpeed(speed / 14.5)
		end
		pose = "Running"
	else
		if emoteNames[currentAnim] == nil then
			playAnimation("idle", 0.1, Humanoid)
			pose = "Standing"
		end
	end
end

function onKeyDown(key)
	if key.KeyCode == Enum.KeyCode.LeftShift then
		Humanoid.WalkSpeed = 23
		
		playAnimation("run", 0.1, Humanoid)
		pose = "Running"
	end
end

function onKeyUp(key)
	if key.KeyCode == Enum.KeyCode.LeftShift then
		Humanoid.WalkSpeed = 16
		
		playAnimation("walk", 0.1, Humanoid)
		pose = "Running"
	end
end

UIS.InputBegan:Connect(onKeyDown)
UIS.InputEnded:Connect(onKeyUp)```

There are two things that could be a problem here I believe of, one you are using an animation created by a group or basically not made from your account if it is your game. Or if you have a group game the animation is not created by the group. The second problem could be that you need to set the animation to an action, so it will play no matter what.

It’s definitely not anything with a group. I’ll set the animation to action, but won’t that override tool animations?

yes it will, but only the hand that is holding the tool will change. What I mean is that if it is not an action every part except for the hand will animate correctly. You also can try other animation priorities like movement just to test and see if they work.

Despite setting the animation to action, the walk animation still plays.

Is it not playing the animation, or the animation speed is not changing? Because I do not see anything on your script that changes the animation speed for your running animation.

The animation does not play.
XXXXXXXXXX

I feel like this top script might be the problem, when do you call the function onRunning?

This is the generic ROBLOX animation script. When the player fires the run event.

I figured out it was because of the “poses”. I had to make a new pose for sprinting.

2 Likes