Check if player is running

so im trying to make a loop that waits then check if the player is running, but it either automatically gives steps or dosent at all. how do you fix this?

Hey!
This article is talking about Humanoid’s function, that returns humanoid’s current state (for example running, falling, swimming, etc…).

ok well now its like this:

The amount of ifs and ends aren’t equal, you need to remove one end from the code

I wish Lua uses C’s “if (statement) { }”, this is an example why.

local Humanoid = Character.Humanoid; --// Character can be found from characteradded and other means.

Humanoid.Running:connect(function(speed)
    if speed <= 0 then
        return --// Idle
    end
    --// Code
end)

I guess you could also flip it depending on how you like to code.

local Humanoid = Character.Humanoid; --// Character can be found from characteradded and other means.

Humanoid.Running:connect(function(speed)
    if speed > 0 then --// Not Idle
        --// code
    end
end)
2 Likes

Im not sure how to fix your problem but try to keep your code neat so its easier to find a problem.

I see, you are getting an error into console, as well as you are missing one end).

The ammout of ends is equal, you probably missed the while loop :slight_smile: but there is missing one end)

You can get the player’s current state by using Humanoid:GetState. In your use case, it would be Enum.HumanoidStateType.Running, read up more here

If you’d like a function to fire whenever the humanoid begins running, you can connect this to a function using this event:

humanoid.StateChanged:Connect(function(oldState, newState)
     if newState == Enum.HumanoidStateType.Running then
          -- player is now running!
     end
end)

thx it works

30characters argh

I highly recommend not using that, It’s bad practice. getstate is usually used for things like double jumping.

1 Like

I see, humanoid.Running is a much better counterpart to what I suggested, maybe I’m thinking too advanced. That hacky “movedirection” thing in an above post looks like bad practice however…

2 Likes

i used if movedirection ~= 0,0,0