How would I determine if a player is moving or not/idle or walking

Hey everyone, I want to be able to see if a player is standing still or moving.

Ex: I want to do some kind of custom animations how would I know if the player is idle or walking/running

I tried to search about humanoid state type but I found nothing that could lead me to determine if a player is idle or not :confused:

All Help would be appreciated :happy3:

3 Likes

You could check the Humanoid’s MoveDirection and see if it’s equal to the Vector3 0, 0, 0 or not. If it’s not, then it’s walking. If it is equal to 0, 0, 0, then it’s idle.

5 Likes

I will try that right away thx for repling.

1 Like

It works! but there is still a slight problem. I want to change and load different animations while the player is walking.Let me explain, if a player is idle and then starts moving I want a different animation to load.

its a slight problem because if a player stays idle and then try’s to move he still has the idle animation loaded in. but when a player is already moving the he has the walking animation and when he stops he dosent idle :confused:

Here is my current script:

local uis = game:GetService("UserInputService")

local plr = game.Players.LocalPlayer
local Char = plr.Character or plr.CharacterAdded:Wait()
local humanoid = Char:FindFirstChildWhichIsA("Humanoid")
-- Animations
local animTrackWalk = humanoid:LoadAnimation(game.ReplicatedStorage.Animations.AnimationCrouchWalk)
local animTrackIdle = humanoid:LoadAnimation(game.ReplicatedStorage.Animations.AnimationCrouchIdle)
-- Camera
local camera = game.Workspace.CurrentCamera
local hrp = Char:FindFirstChild("HumanoidRootPart")

uis.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.C then
		repeat
			if humanoid.MoveDirection ==  Vector3.new(0,0,0) then
				camera.CameraSubject = hrp
				animTrackIdle:Play()
				humanoid.WalkSpeed = 8
				humanoid.JumpPower = 0
			else
				camera.CameraSubject = hrp
				animTrackIdle:Stop()
				animTrackWalk:Play()
				humanoid.WalkSpeed = 8
				humanoid.JumpPower = 0
			end
		until uis.InputEnded
	end
end)

uis.InputEnded:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.C then
		camera.CameraSubject = humanoid
		animTrackWalk:Stop()
		animTrackIdle:Stop()
		humanoid.WalkSpeed = 16
		humanoid.JumpPower = 50
	end
end)

If you just need to replace animations, you can change the AnimationId of the animations in the default Animate script in the character.
image

2 Likes

You can just check if the character’s idle track is playing.

its not that simple I am using custom animations

it’s a slight problem because if a player stays idle and then tries to move he still has the idle animation loaded in. but when a player is already moving he has the walking animation and when he stops he doesn’t idle :confused:

1 Like

You can use the player.Idled function.

2 Likes

I will try that right now thx for sticking with me.

1 Like

I usually use a loop to check to velocity of the humanoid root part. If the absolute value of the velocity’s x or z is above something like 1 then I know it’s moving.

1 Like

I still have the problem, let me explain it. I have two animations, I walking one and an idle one. when you press the key C it chooses between idle and walking because of the code. The only problem is that when I am Idle and walk the animation doesn’t switch to walking anim here is the script:

local uis = game:GetService("UserInputService")

local plr = game.Players.LocalPlayer
local Char = plr.Character or plr.CharacterAdded:Wait()
local humanoid = Char:FindFirstChildWhichIsA("Humanoid")
-- Animations
local animTrackWalk = humanoid:LoadAnimation(game.ReplicatedStorage.Animations.AnimationCrouchWalk)
local animTrackIdle = humanoid:LoadAnimation(game.ReplicatedStorage.Animations.AnimationCrouchIdle)
-- Camera
local camera = game.Workspace.CurrentCamera
local hrp = Char:FindFirstChild("HumanoidRootPart")

uis.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.C then
		repeat
			if humanoid.MoveDirection ==  Vector3.new(0,0,0) then
				camera.CameraSubject = hrp
				animTrackIdle:Play()
				humanoid.WalkSpeed = 8
				humanoid.JumpPower = 0
			else
				camera.CameraSubject = hrp
				animTrackIdle:Stop()
				animTrackWalk:Play()
				humanoid.WalkSpeed = 8
				humanoid.JumpPower = 0
			end
		until uis.InputEnded
	end
end)

uis.InputEnded:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.C then
		camera.CameraSubject = humanoid
		animTrackWalk:Stop()
		animTrackIdle:Stop()
		humanoid.WalkSpeed = 16
		humanoid.JumpPower = 50
	end
end)

Hey there I believe you’re trying to do crouched animations.
If so then u don’t need two animations.

The crouched moving animation is enough.

So u have to set the animation playing speed to 0 when the player is not moving which will pause the animation.

For more info look into this.

AnimationTrack | Documentation - Roblox Creator Hub.

1 Like
humanoid.Running:Connect(function(Speed)
   if speed > 0.1 then -- running >
      print("running")
   else
      print("running")
   end
end)
1 Like

try to use this local script it should work

local player = game.Players.LocalPlayer
local human = player.Character.Humanoid
local walkanim = human:LoadAnimation(script:FindFirstChild("walkanim"))
local idleanim = human:LoadAnimation(script:FindFirstChild("idleanim"))

local RunService = game:GetService("RunService")
RunService.Heartbeat:Connect(function()
	if hum.MoveDirection.Magnitude > 0 then
		idleanim:Stop()
        walkanim:Play()
        
	else
        walkanim:Stop()
		idleanim:Play()
	end
end)

Oh 10 months later i see ;-;
I think i am late.

2 Likes

Yeah, I think he already finished it…