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

How do I check a humanoid when they stopped moving from a running state?

Asked by
Neu_Dev 22
3 years ago
Edited 3 years ago

I have a custom animation and wanted to implement it for the player. a Humanoid has its own Event which is Running or StateChanged.

The only way I can manage to do this is by checking the player is running or using the StateChanged event.

Humanoid.Running:Connect(function()
    -- Insert animation here
end)

--OR

Humanoid.StateChanged:Connect(function(OldState, NewState)
    -- Insert animation here
end)

I tried various options:

  1. I tried to check if the player's velocity is equal to 0 (for some reason the velocity never gets to 0)

  2. I tried to check if the NewState will changed to Nil or None when doing nothing (After Running) Since there is a Enum.HumanoidStateType.None but the "NewState" always prints out as Running or nothing at all when stopped running.

I'm just having trouble finding ways to check if the playing is idle.. Or is there a thing out there that I don't know.. to easily check if the player is idle/not moving.

Thanks!

2 answers

Log in to vote
1
Answered by
imKirda 4491 Moderation Voter Community Moderator
3 years ago
Edited 3 years ago

Humanoid.Running returns Speed which is Humanoid's current speed, you can check if it's 0 and if it is then he stopped moving

Humanoid.Running:Connect(function(Speed)
    if (Speed == 0) then
        --/Humanoid has stopped moving because if Running fired then
        --\it means that humanoid has moved, if the speed is 0 and he
        --\moved then obviously he was running bu stopped
    end
end

Is that what do you mean?

Or you want to check if he IS idle right now? You would use Humanoid.MoveDirection, it's a Vector3 value which represents direction in which Humanoid is moving right now, if it's 0, 0, 0 then he is idle

if ( Humanoid.MoveDirection == Vector3.new(0) ) then
    --/This will only pass if statement if MoveDirection is 0:
    --\this means he is not moving
end

Sources

Humanoid.Running

Humanoid.MoveDirection

0
I have never thought of that! Thank you for this answer! would definitely try both options to see what's more consistent Thanks! Neu_Dev 22 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

You could also just constantly update 2 variables, one of which you update 1 second later then the other, and if they're the same you could run the code.

0
This is also a good idea but, I think it's more consistent for me to use the "Running" event from humanoid but the idea here could help me in different problems. thanks! Neu_Dev 22 — 3y

Answer this question