Whats the most Optimized way to Check if a Player/NPC starts or stops running

Hey there everyone,

Currently I’ve looked around on the Forum a lot and I’ve been trying to find an optimized way to check when the player stops running, but most of them is this:

RunService.RenderStepped:Connect(function()
   if ...
end)

Humanoid.Running also sadly doesn’t work for me as it only fires when the Player/NPC starts running but not when they stop running.

Is there any other Optimized way to do this or is this the only method that could check if the Player starts moving or stops moving, most preferably using a callback rather than a loop
Help would be greatly appreciated!

You can try using Humanoid:GetPropertyChangedSignal("MoveDirection") to detect if the player’s/NPC’s humanoid is moving or not:

Humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
	if Humanoid.MoveDirection.Magnitude > 0 then
		print("Player/NPC is moving!")
	else
		print("Player/NPC has stopped moving!")
	end
end)

according to doc, Humanoid.Running will fire when it stopped. catch the argument for the speed

Humanoid.Running:Connect(function(speed)
  if speed > 0 then
    isRunning = true
  else
    isRunning = false
  end
end)

you can also check state changed

Humanoid.StateChanged:Connect(function(oldState, newState)
  if newState == Enum.HumanoidStateType.Running then
    isRunning = true
  elseif oldState == Enum.HumanoidStateType.Running then
    isRunning = false
  end
end)