Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
4

How to know if a humanoid is idle?

Asked by
Ribasu 127
6 years ago

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!

0
You can check the Torso's velocity to see if the player/npc is moving Amiaa16 3227 — 6y

2 answers

Log in to vote
4
Answered by
nilVector 812 Moderation Voter
6 years ago
Edited 6 years ago

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
0
Great answer! skitsuno 0 — 3y
Ad
Log in to vote
0
Answered by
Prestory 1395 Moderation Voter
6 years ago
Edited 6 years ago

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

0
That's not a property. It's an event Amiaa16 3227 — 6y

Answer this question