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

How to check when player is walking and stops walking?

I make guns on roblox whenever I feel like it. I decided to try to add something to them. A walking animation. I checked Venvious' Avert the Odds II game and I couldn't find anything that showed when the player is walking or not. But it still has a walking animation! I looked to see how to check if a player is walking and found you do this:

Player.Character.Humanoid.Running:connect(function(speed)
	print("Speed: "..speed)
end)

So I tried that. But I found myself stuck. I needed to find out how to check if a player has STOPPED walking! I would look at TurboFusion's gun scripts, but within the first 25 lines I get confused. How can you check if a player has stopped walking?

2 comments

0

Did you test yet?

0

lightpower, the speed measures the velocity the player is going at. I tested it.

2 answers

✓ Accepted answer

To check if the player is walking or not, we need to see what speed its. An int value so basicly a number. When a player stops walking it returns 0. If it's higher than 0 then they're walking,

Player.Character.Humanoid.Running:connect(function(speed) --I hope player is a variable of an actual player.
	if speed == 0 then --If they are not walking,
		print(Player.Name.." has stopped walking.")
	elseif speed > 0 then --If they started walking or is walking.
		print(Player.Name.." is walking.")
	end
end)

I hope this helps.

3 comments

0

I think it will. Let me test it...

0

I thought it only fired when the player is running? shouldn't that mean it will never return 0 since it won't fire at 0?

0

It works! I tested the function while printing the speed, and this is what happened. When I walked it said Player1's Speed: 8.12048... and then when I stopped it said Player1's Speed: 7.194... then Player1's Speed: 0. So it's not the best, but it works!

You could also use the Velocity property.

local Torso = ???
Torso.Changed:connect(function(val)
	if val == "Velocity" then
		print("Speed changed: "..Torso.Velocity)
	end
end)

1 comment

0

That would be a bit buggy, because if the player is falling then it will play the walking animation which is not what I want. Thanks anyway

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