0

Checking for player movement

chrono2 189
8 years ago

Is there a way to check and see if a player is walking in a localscript?

1
Unclear 1776
8 years ago

You can use the Running event to do this task for you and change a boolean every time it triggers.

Here's some code for you to inspect...

local humanoid  = game.Players.LocalPlayer.Character.Humanoid
local isRunning = false

humanoid.Running:connect(function(speed)
isRunning = speed ~= 0
end)

1
Is humanoid always non-nil? Or should :WaitForChild() be used? MrNicNac 855 — 8y
0
Humanoid is not always non-nil. I was merely putting this code out there for inspection, though it's nice of you to point that out for other users! Unclear 1776 — 8y
1
jobro13 980
8 years ago

Yes, you can. The humanoid's Running event can be used:

local Player = game.Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character.Humanoid

Humanoid.Running:connect(function(Walkspeed)
print("Player has started walking! The walk speed is: "..Walkspeed.."!")
end)

0

Use the Humanoid.Running event.

game.Players.LocalPlayer.Character.Humanoid.Running:connect(function()
print("Player is walking")
end)

0
When the player stops walking the event also fires. Everesty 1006 — 8y
0
local Walking = false