How to detect if a character is moving or not

I’m attempting to make a running script that only deactivates when the player stops moving/running. When the player presses the button they’ll start moving and running; I want the player to stop running automatically when they stop moving. I’ve tried using the humanoids move direction but it only returns 0,0,0 which doesn’t help.

Why not just have the player click the button again to stop running?
Well If I did that a player could stand still and do other stuff while the run animation is still playing making it appear weird

Code below:

RunBtn.TouchTap:Connect(function(touchPositions: {any}) 
	if IsTapped then return end
	
	IsTapped = true
	RunStart(true)

	RunConnection = RunService.RenderStepped:Connect(function(deltaTime: number) 
		if Humanoid.MoveDirection == Vector3.new(0,0,0) then
			RunEnd()
			RunConnection:Disconnect()
			IsTapped = false
		end
	end)
end)
1 Like
if Humanoid.MoveDirection.Magnitude > 0 then
1 Like

Also instead of running RunService RenderStrepped you can just do…

Humanoid:GetPropertyChangedSignal:Connect(function()
        if Humanoid.MoveDirection.magnitude > 0 then -- if it's not > try <
			RunEnd()
			RunConnection:Disconnect()
			IsTapped = false
		end
end)

I’m no genius here but I think you should have put Humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function() instead of Humanoid:GetPropertyChangedSignal:Connect(function()

Oh yeah, mb I forgot lol
That’s correct though.

This is what I used, but this is for all players. You might need to adjust it to make it for a single player.

for i, player in ipairs(game.Players:GetPlayers()) do--
		if player.Character.Humanoid.MoveDirection ~= Vector3.new(0,0,0)then
			player.Character.Humanoid.Health = 0
			end
	end

That’s basically the same thing I did…

1 Like