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:
1 | if humanoid.MoveDirection = = Vector 3. new( 0 , 0 , 0 ) |
2 | and humanoid:GetState() ~ = Enum.HumanoidStateType.Jumping |
3 | and humanoid:GetState() ~ = Enum.HumanoidStateType.FreeFall then |
4 | -- humanoid is idle |
5 | 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