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

What is a reliable way to check if a player is moving (walking only)?

Asked by 5 years ago
Edited 5 years ago

Im currently using the StateChanged event to find when the player is moving around, but it doesn't seem to work right. It doesn't register the player stopping and walking again very well, and it's unreliable overall. I previously tried getPropertyChangedSignal on velocity in the humanoid root part and checked if the velocity ever reached 0, as a way to see if the player is moving. Not only did it not work, but it would have registered a jump or climb as the player moving, which I don't want. How else can I determine when the player is walking?

    self.hum.StateChanged:connect(function(old,new)

        if new == Enum.HumanoidStateType.Running then
            print("You're moving")
            self.isMoving = true
        elseif old == Enum.HumanoidStateType.Running then
            print("You're not moving")
            self.isMoving = false
        end
    end

1 answer

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

The default walking speed is 16 so just get the speed from the speed parameter.

EXAMPLE:

game.Workspace.Player.Humanoid.Running:connect(function(speed)
    if speed > 16 then
        print("Player is running")
    elseif speed == 16
        print("Player is walking")
    end
end)
Ad

Answer this question