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

How to check when player is walking and stops walking?

Asked by 9 years ago

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?

0
Did you test yet? EzraNehemiah_TF2 3552 — 9y
0
lightpower, the speed measures the velocity the player is going at. I tested it. EzraNehemiah_TF2 3552 — 9y

2 answers

Log in to vote
0
Answered by 9 years ago

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.

0
I think it will. Let me test it... lightpower26 399 — 9y
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? aquathorn321 858 — 9y
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! lightpower26 399 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

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)
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 lightpower26 399 — 9y

Answer this question