Why is sprinting animation stacking?

I’ve been working on this sprint script for a little while to get it as perfect as possible and I have come to a script that works decently well. However, when I change directions while sprinting it seems to either stack the animation or stop it from playing past a certain point.

The main code:

repeat task.wait() until UIS:IsKeyDown(Enum.KeyCode.LeftShift) and Humanoid.MoveDirection.Magnitude > 0
					Humanoid.WalkSpeed = Speed
					SprintingTween:Play()
					local Anim = Instance.new('Animation')
	Anim.AnimationId = 'rbxassetid://11567015463'
					local PlayAnim = Character.Humanoid:LoadAnimation(Anim)
						PlayAnim:Play() 
	warn("running")
	
	
		repeat task.wait() until not UIS:IsKeyDown(Enum.KeyCode.LeftShift) or Humanoid.MoveDirection.Magnitude <=0
				Humanoid.WalkSpeed = DefaultWalkingSpeed
				WalkingTween:Play()
				PlayAnim:Stop()
	end)

A video of the issue:
robloxapp-20221130-1612421.wmv (2.6 MB)

Are you showing us the full script?

No but the rest of it is mostly just variables

1 Like

You should store the run animation inside a variable outside of all that, your constantly creating it when pressing down left shift, which may not be the problem but its good practice to not do that

image

That did help it from stacking, but now it resets the animation when I change directions
robloxapp-20221130-1702541.wmv (1.1 MB)

Check if the animation isnt already running using this
@Qmenator

if not PlayAnim.IsPlaying then
 -- play the animation
end

https://create.roblox.com/docs/reference/engine/classes/AnimationTrack#IsPlaying``

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.