local path = game:GetService("PathfindingService")
local dis = math.huge
local torso = script.Parent.Torso
function find(pos)
	for i,v in pairs(game.Workspace:GetChildren())do
		if v.ClassName == "Model" and v ~= script.Parent then
			local humanoid = v:FindFirstChildWhichIsA("Humanoid")
			if humanoid and humanoid ~= nil and v:FindFirstChild("HumanoidRootPart") then
				if (v.HumanoidRootPart.Position - pos).Magnitude < dis then 
					local space = (v.Head.Position - pos).Magnitude
					print(v.Name)
					return space
				end
			end
		end
	end
end

while true do
	wait(1)
	local patt = path:CreatePath()
	local target = find(torso.Position)
	patt:ComputeAsync(torso.Position, Vector3.new(target))
	if target ~= nil then
		script.Parent.Humanoid:MoveTo(Vector3.new(target))
	end
end

This is what I got, how could I fix and improve it?, The name of the NPC was right but the AI was going towards somewhere else. I've post this but no one answered so I'm posting it again. Thankyou