What's the absolute best way to detect when a humanoid is idle?

I’ve seen multiple posts but I can’t seem to replicate them. Can anyone help with this and give me the most logically plausible solution?

1 Like

https://developer.roblox.com/en-us/api-reference/event/Humanoid/StateChanged
Check out the 3rd bullet point of the See also:

2 Likes

Another way is to check if Humanoid.MoveDirecton’s magnitude is 0. But, do not use .Magnitude as we can just use the dot product instead (magnitude has square root calculations which can be expensive). You can simply do:

if hum.MoveDirection:Dot(hum.MoveDirection) == 0 then


end

The dot product of a vector with itself is its magnitude squared. Meaning, if the magnitude if 0 or 1, the square would also be 0 or 1. Speaking of 0 and 1, MoveDirection’s magnitude (and dot product with itself) can only be those numbers. If the player is moving ever so slightly, it still makes the vector 1 stud long, there is no in-between. Similarly, you can check if the player is moving using two ways:

if hum.MoveDirection:Dot(hum.MoveDirection) == 1 then


end

--or
if hum.MoveDirection:Dot(hum.MoveDirection) > 0 then

end

--both are valid
10 Likes

You could see if their velocity is less than 1. If their velocity is less than 1, they are likely idle.

1 Like

Better way:

if hum.MoveDirection == Vector3.zero then

end

Don’t unnecessarily overcomplicate it

1 Like