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

How would you detect if a Player moved, ignoring the Idle animation?

Asked by 8 years ago

I was wondering if anyone can tell me if there is something like .Moved for a Player's Humanoid to detect when a Player moves, ignoring the Idle Animation. Only thing I have been able to think of is using a while wait() do loop.

Script I tried:

local Player = game.Players.LocalPlayer
local Pos = Player.Character.Torso.Position

while wait() do
    if Pos ~= Player.Character.Torso.Position then
        Pos = Player.Character.Torso.Position
--      print(Pos)
    end
end

Any help appreciated.

1 answer

Log in to vote
0
Answered by
Lamar 45
8 years ago

To expand on DevSean's wiki link, there are multiple events for the Humanoid class that will be fired depending on the Humanoid's state. Running is one such event. There are also events for Climbing, Swimming, etc, but without context it's easy to assume that Running is the event you want. Thus, you want something like this:

local Player = game.Players.LocalPlayer
Player.Character.Humanoid.Running:connect(function()
    --your code
end)

There's also a speed argument for the Running event. You're better off using something closer to the example in the Wiki, which makes use of the speed argument; my code will fire again when you stop walking.

Ad

Answer this question