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

RunService.stepped function is not working properly?

Asked by 5 years ago
   local Step = game:GetService("RunService")



Step.Stepped:connect(function()

print("Stepped")

end)

It prints "Stepped" 24/7, even when I am not moving. How would I fix this?

1 answer

Log in to vote
0
Answered by 5 years ago

I believe you're misunderstanding what RunService and a step in that context are.

RunService is a service built around managing time and for managing the context everything is running in (In Studio, as a client, as the server).

The Stepped event is an event that fires every frame, which is why it was printing so much.

To print whether or not they are running everytime that changes, you could use the StateChanged event of Humanoid. Here's an example of this:

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(char)
        local humanoid = char:WaitForChild("Humanoid")

        humanoid.StateChanged:Connect(function(oldState,newState)
            --Checking the current and last state
            if newState == Enum.HumanoidStateType.Running then
                print("Running")
            elseif oldStae == Enum.HumanoidStateType.Running then
                print("Stopped running")
            end
        end)
    end)
end)

You can read up on these topics a bit more at RunService.Stepped Humanoid.StateChanged

Ad

Answer this question