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

How can I check if a player is in idle state?

Asked by 5 years ago

As you know there is no Enum.HumanoidStateType.Idle so how can i check if the player is in idle state ?

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

This might work:

local player = game.Players.LocalPlayer
local humanoid = player.Character:WaitForChild("Humanoid")
humanoid.StateChanged:connect(function()
if humanoid.MoveDirection == Vector3.new(0, 0, 0) and humanoid:GetState() ~= Enum.HumanoidStateType.Running and humanoid:GetState() ~= Enum.HumanoidStateType.Jumping and humanoid:GetState() ~= Enum.HumanoidStateType.Freefall then
print("idle")
end
end)

btw, make sure the first 2nd line to the 4th line are one line, Since there is no HumanoidStateType.Idle, we can only listen for the Vector3 of the humanoid's RootPart as stated in the wiki

Or rather you can use 'if not' (Don't actually use this script, it is just an example)

if not Enum.HumanoidStateType.Running then
if not Enum.HumanoidStateType.Jumping then
if not Enum.HumanoidStateType.Freefall then
if not Enum.HumanoidStateType.Climbing then
etc...
print("Humanoid is idling")

-- These states that if the humanoid is 'not' doing these certain StateType then it should print "Humanoid is idling"

Hopefully it helps...

0
Error in logic, second script would result in false every time as the Enumeration values described all exist. Did you mean to compare the humanoid's current state to the enumeration values? In both situations, you'd probably benefit from having a separate function using a loop and having the non-idle states in a table doing comparisons until one is false returning the result. M39a9am3R 3210 — 5y
Ad

Answer this question