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

HI wow can i verify that a player is walking/runninjg?

Asked by 3 years ago

So i need to verify with a script/local spript if it works

0
You can check if Humanoid.MoveDirection ~= Vector3.new(0, 0, 0). [MoveDirection] is current humanoid move direction in a Vector3 value, if it's 0, 0, 0 he is not moving, else he is. imKirda 4491 — 3y
0
Or check the current state of the Humanoid, using GetState() if applicable. DeceptiveCaster 3761 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

Each player's character model has a Humanoid which controls how the player's character moves and stuff like that. There's an event you can use called Running which triggers when the player starts walking/running:

-- Note: This is a server script
game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(char)
        char.Humanoid.Running:Connect(function(speed)
            if speed > 0 then
                print("Humanoid is running at " .. speed)
            else
                print("Player has stopped running")
            end
        end)
    end)
end)

The speed argument is the WalkSpeed of the player. While I was testing this event, I discovered that when the player goes from running to standing still, the event reads their current speed as 0.

If you need to check if the player is walking/running instantaneously without using an event, you can check the MoveDirection property which returns a unit vector that describes the direction the player is moving in:

-- humanoid argument is a player's Humanoid
function isRunning(humanoid)
    return (humanoid.MoveDirection ~= Vector3.new(0, 0, 0))
end

The condition inside the parentheses only checks if the player is running since Vector3.new(0, 0, 0) is the value of MoveDirection when the player is not moving. When true is returned by the function, it means the player is moving. When false is returned by the function, it means the player is not moving.

I hope this answers your question :)

Ad

Answer this question