Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

Checking for player movement

Asked by
chrono2 189
6 years ago

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

4 answers

Log in to vote
1
Answered by
Unclear 1776 Moderation Voter
6 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 — 6y
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 — 6y
Ad
Log in to vote
1
Answered by
jobro13 980 Moderation Voter
6 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)
Log in to vote
0
Answered by 6 years ago

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 1016 — 6y
Log in to vote
0
Answered by
Everesty 1016 Moderation Voter
6 years ago

Humanoids have a Running even which is fired whenever the speed of the character changes. Use that and some logic, and you have a way to tell if the player is walking or not.

local Walking = false

game.Players.LocalPlayer.Character:WaitForChild("Humanoid").Running:connect(function(Speed)
    Walking = (Speed > 0)
end)

Answer this question