How can i detect if a humanoid is moving?

So basically, i have a problem, im making a game that i need a script to check if the humanoid is running or not, i specifically want it to run the animation, which perfectly does fine. But theres a thing, when you move around like your orientation changes, the animation replays and looks like its cutted, hope i can get some help.

local Anim = script.Parent.AnimControl:LoadAnimation(script.Walk)

script.Parent.Parent.Humanoid.Running:Connect(function(speed)
	if speed > 0 then
		Anim:Play();
	else
		Anim:Stop();
	end
end)

Video:

4 Likes

Can’t you set the default animations?
Using Animations in Games
It should work fairly well.

1 Like

However that would be a nice option, but its a separate model from the player, so i want to kinda make like when you move, a part animation is played. Not the player itself. but thanks for the contribution.

2 Likes

(a visual may help)

Not sure exactly what this means and if you can explain better I may be able to help more- but an alternative to monitoring the running property is to check velocity.

1 Like

How checking velocity? i never heard of that.

Heres the visual you asked for:

1 Like

Would using Humanoid.StateChanged work? Your code would look something like this:

Humanoid.StateChanged:Connect(function(oldState, newState)
if newState = Enum.HumanoidStateType.Running then
--do stuff
end
end)

I’m not sure if I got the new and old args the wrong way round, so, if it doesn’t work, try switching them.

1 Like

I believe you can do humanoid.MoveDirection.Magnitude and check if it is greater than zero.

Edit: So I double checked, and it is correct. You should be able to do something like:

if Humanoid.MoveDirection.Magnitude > 0 then
    -- do stuff here
end

Hope this helps!

3 Likes

To add on, if you want it to detect it constantly you can do this:

Humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
	if Humanoid.MoveDirection.Magnitude > 0 then
		if Anim.IsPlaying == true then return end
		Anim:Play();
	else
		Anim:Stop();
	end
end)

(I have a question, are you making a JJBA game? If so thats cool. If not it is still cool.)

10 Likes

Works perfectly, thanks, now this is not a problem thanks for solving it!

3 Likes

Also, jjba game :wink: yeah, you were right

3 Likes