NPC walkspeed bug?

So basically I have an NPC who slows down when the player isn’t moving, the thing is the NPC only speeds up if I go near it, I have no clue why. It says in properties the correct speed but in game it doesn’t update. Ignore the animation as that works fine, its just the actual movement that’s broke.
Script below is in StarterCharacterScripts and the other script is in the NPC.

local runService = game:GetService("RunService")
Anim = game.Workspace.NPC.Script.Animation
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local player = game.Players:GetPlayerFromCharacter(character)
local a = game.Workspace.NPC.Humanoid:LoadAnimation(Anim)


function updateEffect()

	if humanoid.MoveDirection.Magnitude > 0 then
		humanoid.WalkSpeed = 14
		game.Workspace.NPC.Humanoid.WalkSpeed = 12
		a:AdjustSpeed(0.5)

	else 
		humanoid.WalkSpeed = 0
		game.Workspace.NPC.Humanoid.WalkSpeed = 0.48
		a:AdjustSpeed(0.02)
		
	end
end

runService.RenderStepped:Connect(updateEffect)
a:Play()

function findNearestUpperTorso(pos)
	local list = game.Workspace:children()
	local lowertorso = nil
	local uppertorso = nil
	local dist = 80
	local temp = nil
	local human = nil
	local temp3 = nil
	for x = 1, #list do
		temp3 = list[x]
		if (temp3.className == "Model") and (temp3 ~= script.Parent) then
			temp = temp3:findFirstChild("LowerTorso")
			temp = temp3:findFirstChild("UpperTorso")
			human = temp3:findFirstChild("Humanoid")
			if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then
				if (temp.Position - pos).magnitude < dist then
					uppertorso = temp
					dist = (temp.Position - pos).magnitude
				end
			end
		end
	end
	return uppertorso
end

while true do
	wait(0.1)
	local target = findNearestUpperTorso(script.Parent.UpperTorso.Position)
	if target ~= nil then
		script.Parent.Humanoid:MoveTo(target.Position, target)
	end
end 


Thanks.

maybe Network ownership will fix the problem,

local Dummy = script.Parent

Dummy.HumanoidRootPart:SetNetworkOwner(nil)

Sorry this didn’t work thanks for the suggestion tho! :grinning: