How to temporarily stop walk animation for sprinting?

I want my walk animation (which uses the default animate script, but I’ve replaced the walk animation) to stop and be replaced by my sprinting animation

My current, non working code:

---------- Services ---------- 

local UIS = game:GetService("UserInputService")
local RS = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

---------- Variables ---------- 

local Plr = Players.LocalPlayer

if not Plr.Character then
	Plr.CharacterAdded:Wait()
end

local Char = Plr.Character

local Anim = Instance.new("Animation")
Anim.AnimationId = "rbxassetid://"..108959713317543

local RunAnim: AnimationTrack = Char:WaitForChild("Humanoid"):LoadAnimation(Anim)
local WalkAnim = Char.Animate.walk.WalkAnim

local Sprinting = false

---------- Funcionality ---------- 

UIS.InputBegan:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.LeftShift then
		Sprinting = true
	end
end)

UIS.InputEnded:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.LeftShift then
		Sprinting = false
	end
end)

---------- Anim ---------- 

while task.wait(.1) do
	if Sprinting then
		if Char.Humanoid.MoveDirection.Magnitude > 0 then
			if not RunAnim.IsPlaying then
				WalkAnim:Stop()
				RunAnim:Play()
			end
		end
	else
		print("kerfuffle")
		Char.Animate.Enabled = true
		RunAnim:Stop()
	end
end

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

You can set the priority of the sprinting animation to “Action,” so when you play the sprint animation it will override the default walk animation (which has a lower priority).
Also make sure your sprinting animation is looped.

1 Like

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