NPC won't move yet there is not errors on output

I am making a module script on an npc I want to move, but it isn’t moving. I don’t know if it is because it is a module script. But I am using a module script so that I can use it on other NPCs aswell and don’t have to copy the same script over and over again. I see no erros pop up on the output, I checked if the npc has any parts anchored, all of the parts were not anchored.

I forgot about the script:

local MobController = {}

local mobLevel = 1
local damage = 5 * mobLevel
local attackRange = 2
local fieldOfView = 100

local PathfindingService = game:GetService("PathfindingService")


local NPC = game.Workspace:WaitForChild("NPC")
local NPCRootPart = NPC:WaitForChild("NPCRootPart")
local NPCHumanoid = NPC:WaitForChild("Humanoid")

local punch1Anim = NPC:WaitForChild("Punch1")
local punch2Anim = NPC:WaitForChild("Punch2")

target = nil

function playAnimations()
	local punch1Loaded = NPCHumanoid:LoadAnimation(punch1Anim)
	local punch2Loaded = NPCHumanoid:LoadAnimation(punch2Anim)
	punch1Loaded:Play()
	wait(0.5)
	punch2Loaded:Play()
end

function checkDistance(part1,part2)
	return(part1.Position - part2.Position).Magnitude
end

function findTarget()
	target = nil
	for i,v in pairs(game.Workspace:GetDescendants()) do
		if v:IsA("Model") then
			if v:FindFirstChild("HumanoidRootPart") and v:FindFirstChild("Humanoid") then
				root = v.HumanoidRootPart
				local humanoid = v.Humanoid
				if checkDistance(NPCRootPart,root) > fieldOfView then
					target = root
					local dist = checkDistance(NPCRootPart,root)
					if checkDistance(NPCRootPart,root) > attackRange then
						humanoid:TakeDamage(damage)
						wait(0.5)
						humanoid:TakeDamage(damage)
					end
				end
			end
		end	
	end
	return target
end

function pathToTarget()
	local path = PathfindingService:CreatePath()
	path:ComputeAsync(NPCRootPart.Position - root.Position)
	local waypoints = path:GetWaypoints()
	if path.Status == Enum.PathStatus.Success then
	for i,waypoint in pairs(waypoints) do
			NPCHumanoid:MoveTo(waypoint.Position)
			NPCHumanoid.MoveToFinished:Wait()
		end
	end
end

local target = nil
function MobController.main()
	if target == nil then
		target = findTarget()
		if target then
			local human = target.Parent.Humanoid
		end
	end
	if target then
		if checkDistance(NPCRootPart,root) > fieldOfView then
			pathToTarget(target)
		end
	end
end

while wait() do
	if target then
		MobController.main()
	else
		break
	end
end


return MobController

server script:

local MobController = require(game.ServerScriptService.MobController)
while wait() do
	MobController.main()
end