MoveDirection for NPC's with a humanoid

I’m trying to make a footstep system for an NPC which walks around, and I’ve run into a problem. When trying to use Humanoid.MoveDirection.Magnitude on a server-side script, the magnitude is always 0 regardless of if the humanoid is moving or not. If you’re wondering I am moving the NPC by using Humanoid:MoveTo(). If you’re wondering I have tried to use Humanoid.Running:Connect but it is unreliable since it only plays the footsteps when it finishes walking to a waypoint. If you have any solutions or a way to play footstep sounds on an NPC please reply thanks!

ServerScript:



local CD = true

function playstep()
	local humanoid = script.Parent.Humanoid
	local direction = humanoid.MoveDirection.Magnitude
	local rootPart = script.Parent:WaitForChild("HumanoidRootPart")


		
			if CD and humanoid.MoveDirection.Magnitude > 0 then
	CD = false
	local sound = script.Parent.HumanoidRootPart.Footsteps
local pitch = sound.EqualizerSoundEffect
	local hg = math.random(0,10)
	local lg = math.random(0,10)
	local mg = math.random(0,10)
	
	pitch.HighGain = hg
	pitch.LowGain = lg
	pitch.MidGain = mg
	
		sound:Play()
	sound.Ended:Wait()
			CD = true
			
	end
		playstep()
		
	
end

spawn(playstep)

Rather than checking the humanoid’s move direction, you could try getting its current state to see if it is moving.

local state = humanoid:GetState()

if CD and state == Enum.HumanoidStateType.Running then

end

edit: Ignore this as the humanoid state will also be set to Enum.HumanoidStateType.Running while standing still.