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

RunService.stepped function is not working properly?

   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

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

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