Okay, so I made a game which I'm not gonna really explain about and I made an animation for movement for one of the npcs. It follows the nearest player, and here's part of the code I have right now: (It's an enemy npc)
while wait() do
local player = FindPlayer()
if player ~= nil then
h:MoveTo(player.Character.HumanoidRootPart.Position)
if not walk.IsPlaying and player.Character.Humanoid.Health >= 1 then
walk:Play()
elseif player.Character.Humanoid.Health <= 0 then
walk:Stop()
player.Character.HumanoidRootPart:Destroy()
end
else
h:MoveTo(spawnCF.p)
end
end
Is there any way to detect if the character is moving, and when it does, run the animation?

4 comments
I fixed it up, try it now?
It works when It's not looped, I will now try with the animation looped Edit: It doesn't work with a loop, the animation just keeps going!
I won't leave you hanging, give me a bit to figure this out
the animation not looped looks like he's walking then stop walking but continuing to move