How to animate a group of npcs locally

how do i check when the npcs moves
i used this script but i miss the moving check

for i , folder in ipairs(workspace:WaitForChild("NPCS"):WaitForChild('Zombies'):GetChildren()) do
	print(22)
	local model = folder
	local idleanim = game.ReplicatedStorage.Animations.Zombies.Idle
	local runanim = game.ReplicatedStorage.Animations.Zombies.Run
	local idle = model.Humanoid:LoadAnimation(idleanim)
	local Anim = model.Humanoid:LoadAnimation(runanim)
	idle.Priority = Enum.AnimationPriority.Idle
	Anim.Priority = Enum.AnimationPriority.Movement
	idle:play()
	
	
	
	model.Humanoid.MoveToFinished:Connect(function(reached)
		Anim:Stop()
	end)
	
	
end

You could use : Humanoid.MoveDirection and / or Humanoid.StateChanged

doing something like

Humanoid.StateChanged:Connect(function(oldState, newState)
 if newState == Enum.HumanoidStateType.Running then
    -- play running anim
  else
    -- check if anim is playing and stop it
 end
end)

More can be done in an effort to make the animation transitions more smooth. I believe that you can actually pass an easingTime parameter when stopping animations as well.

You can also change the speed of the animation based on the speed of the player via:

local movementAmount = Humanoid.MoveDirection.Magnitude

AnimationTrack:AdjustSpeed(movementAmount)