Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Checking for player movement

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

4 answers

✓ Accepted answer

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)

2 comments

1

Is humanoid always non-nil? Or should :WaitForChild() be used?

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!

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)

Use the Humanoid.Running event.

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

1 comment

0

When the player stops walking the event also fires.

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.