Check to see if a player is walking?

How can I check if a player is walking in my game? I am wanting to play an animation when a player is walking. Let me know how I can do it.

Here is my script:

local UIS = game:GetService('UserInputService')
local Player = game.Players.LocalPlayer
local Character = Player.Character
local PlayAnim

UIS.InputBegan:connect(function(input)--When a player has pressed LeftShift it will play the animation and it will set the normal walking speed (16) to 35.
	if input.KeyCode == Enum.KeyCode.C then
		Character.Humanoid.WalkSpeed = 11
		local Anim = Instance.new('Animation')
		Anim.AnimationId = 'rbxassetid://10410199944'
		PlayAnim = Character.Humanoid:LoadAnimation(Anim)
		PlayAnim:Play()
	end

	if input.KeyCode == Enum.KeyCode.ButtonX then
		Character.Humanoid.WalkSpeed = 11
		local Anim = Instance.new('Animation')
		Anim.AnimationId = 'rbxassetid://10410199944'
		PlayAnim = Character.Humanoid:LoadAnimation(Anim)
		PlayAnim:Play()
	end
end)

UIS.InputEnded:connect(function(input)
	if input.KeyCode == Enum.KeyCode.C then
		Character.Humanoid.WalkSpeed = 17.5
		PlayAnim:Stop()
	end

	if input.KeyCode == Enum.KeyCode.ButtonX then
		Character.Humanoid.WalkSpeed = 17.5
		PlayAnim:Stop()
	end
end)

This script is in StarterCharacterScripts btw.

Thanks for your help!

Sincerely,

papahetfan

1 Like

You could go the route of checking the MoveDirection of their humanoid, so if they are moved without input the animation also plays

Done with a script similar to:

local Character = game.Players.LocalPlayer.Character

Character:WaitForChild("Humanoid").Changed:Connect(function()
if Character.Humanoid.MoveDirection.Magnitude > 0 then
-- play animation
end
end

1 Like

https://developer.roblox.com/en-us/api-reference/event/Humanoid/Running