How Do I Make A Walk And Run Animation Script

So I want to make a script that allows the player to run when they hold shift with an animation. I also want to have a walk animation when they are not running. I have the Shift to run system but I don’t know how to get the character to play a different animation depending on if they are walking or running.

Here is the script I am using for the run system. I don’t know how to implement the run and walk animations into it

local userInput = game:GetService("UserInputService")
local players = game:GetService("Players")


local sprintSpeed = 15
local walkSpeed = 8

local player = players.LocalPlayer


local function beginSprint(input, gameProcessed)
	if not gameProcessed then        
		if input.UserInputType == Enum.UserInputType.Keyboard then
			local keycode = input.KeyCode
			if keycode == Enum.KeyCode.LeftShift then 
				player.Character.Humanoid.WalkSpeed = sprintSpeed
				
			end
		end
	end
end

local function endSprint(input, gameProcessed)
	if not gameProcessed then
		if input.UserInputType == Enum.UserInputType.Keyboard then
			local keycode = input.KeyCode
			if keycode == Enum.KeyCode.LeftShift then
				player.Character.Humanoid.WalkSpeed = walkSpeed
		
			end
		end
	end
end

userInput.InputBegan:Connect(beginSprint)
userInput.InputEnded:Connect(endSprint)
2 Likes