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)
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