A humanoid can be in many states: running, swimming, fallingdown... here is the full list: https://wiki.roblox.com/index.php?title=API:Enum/HumanoidStateType.
How can I know that a humanoid is idle, though? It's not a state in that list!
Although the HumanoidStateType
Enum does not provide developers with any information regarding the idle state of a Humanoid
(which it really should), there is another way to determine whether a Humanoid
is idle or not, and that is through the MoveDirection property of the Humanoid object.
What this read-only property does is return the Vector3
direction that the player is moving towards. Knowing this, we can conclude that when the player is idle, its MoveDirection
will be 0 in all directions. However, if the Humanoid
is only jumping or falling but not moving, then its MoveDirection is still 0 in every direction. Thus, we can do something like this in our code:
if humanoid.MoveDirection == Vector3.new(0, 0, 0) and humanoid:GetState() ~= Enum.HumanoidStateType.Jumping and humanoid:GetState() ~= Enum.HumanoidStateType.FreeFall then -- humanoid is idle end
You could use the Running Humanoid Property heres a link on how to use it to dectect if the player is idle or not.
https://wiki.roblox.com/index.php?title=API:Class/Humanoid/Running