Check if the player is moving?

I have a custom animation script that uses Humanoid.Running, but the issue here is it doesn’t work while the player is in the air/floating. What’s a way I can check if the player is moving even while floating?

21 Likes

The Humanoid has a property called MoveDirection which determines, as a unit vector, the direction a player is moving in. You can access the Magnitude property and see if it’s greater than 0 to know if there is active movement without relying on what their HumanoidStateType is.

Refer to the code sample on the page.

46 Likes

Can this help with jumping or freefalling?

1 Like

Not sure what you mean to ask there. Are you asking if this can help determine the direction a player is moving in while they’re in an airborne state? Answer is no then, because MoveDirection only describes the movement along a 2D XZ axis (Y is not applicable to MoveDirection). You’ll have to find a different property if you need to work with 3D movement where Y is a value that changes.

You can also intercept when the MoveDirection property changes:

Humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function() 
	print(Humanoid.MoveDirection)
end)
9 Likes

you should do print(Humanoid.MoveDirection.Magnitude)

there are more states for this:

2 Likes

How do you make it so that if the player moves, ONLY the player who moved, it happens to the player that moves specific things

2 Likes