Detect if Humanoid is walking or not and vice versa (if they stopped mid way through)

Title says it all, i just want a simple function that detects if player is walking or not CONSISTENTLY.
No need for a full script
Just an if statement or (a loop).
I need this for a simple “build up speed” script.

You should be able to use the MoveDirection property for this, look in to the code example provided on the wiki page.

I did use that but it doesn’t seem to function properly.
And the only solution was a while loop, but i don’t want a loop.

if Humanoid.MoveDirection.Magnitude > 0 then
    Sprint:Play()
elseif Humanoid.MoveDirection.Magnitude <= 0 then
    Sprint:Stop()
end

If you do not want to use a loop you could use GetPropertyChangedSignal, here is a rough code sample of what that would look like:

humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
	if humanoid.MoveDirection.Magnitude > 0 then -- and not animationTrack.IsPlaying
	   print('start animation')
	else
	   print('stop animation')
	end
end)

image
Tried that and got this many prints, also the sprint animation does not stop playing when player reaches “0”.

Are you checking if the animation is already playing or not?

humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
	if humanoid.MoveDirection.Magnitude > 0 and not Sprint.IsPlaying then
	   Sprint:Play()
	else
	   Sprint:Stop()
	end
end)
local humanoid = character:WaitForChild("Humanoid")
 
humanoid.Running:Connect(function(speed)
	if speed > 0 then
		print('Plr is currently walking')
	else
		print('Plr is currently not walking')
	end
end)

Did made sure and it still doesn’t stop.

if Humanoid.MoveDirection.Magnitude > 0 and not Sprint.IsPlaying then
	local Tween = TS:Create(plr.Character.Humanoid, TweenInfo.new(2), {WalkSpeed = 32})
	Tween:Play()
	SpeedTween:Play()
	Tween.Completed:Connect(function()
			Sprint:Play()
	end)
else
	Sprint:Stop()
	TS:Create(plr.Character.Humanoid, TweenInfo.new(2), {WalkSpeed = 16}):Play()
	WalkTween:Play()
end
end)

Humanoid.Running runs fine but the animation plays three times due to Tween.Comepleted :frowning:

1 Like

Just add a debounce

local debounce = false
local humanoid = character:WaitForChild("Humanoid")
 
humanoid.Running:Connect(function(speed)
	if speed > 0 then
		if debounce == false then
			debounce = true
			print('Plr is currently walking')
		end
	else
		print('Plr is currently not walking')
		debounce = false
	end
end)
1 Like

what do you mean by “Detect if humanoid is walking or not”

Just detect if player is walking or not.

This worked! Thank you, it also solved the issue of sprinting animation playing even when player is not walking.

Humanoid.Running:Connect(function(speed)
	if speed > 0 then
		if debounce == false then
			debounce = true
	local Sprint = TS:Create(plr.Character.Humanoid, TweenInfo.new(2), {WalkSpeed = 32})
	Sprint:Play()
	SpeedTween:Play()
	Sprint.Completed:Connect(function()
				Anim:Play()
			end)
	end
else
	debounce = false
	Anim:Stop()
	TS:Create(plr.Character.Humanoid, TweenInfo.new(2), {WalkSpeed = 16}):Play()
	WalkTween:Play()
	end
end)

Glad you resolved the issue, I made a simple mistake with the code I provided so here is the fix for future reference:

humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
	if humanoid.MoveDirection.Magnitude > 0 then
       if not Sprint.IsPlaying then
          Sprint:Play()
       end
	else
	   Sprint:Stop()
	end
end)
1 Like