Issues With Waypoint Service

Right now I am currently working on an NPC Module allowing me to spawn in npcs. I have an issue with waypoint service though. Currently this is in a module. Here is my code:

function commands.MoveTo(Char, Pos)

	local PathfindingService = game:GetService("PathfindingService")


	local path = PathfindingService:CreatePath()

	
	local character = Char

	local humanoid = Char:WaitForChild("Humanoid")

	local TEST_DESTINATION = Pos


	local waypoints
	local nextWaypointIndex
	local reachedConnection
	local blockedConnection

	local function followPath(destination)
		-- Compute the path
		local success, errorMessage = pcall(function()
			path:ComputeAsync(Char.PrimaryPart.Position, destination)
		end)

		if success and path.Status == Enum.PathStatus.Success then
			-- Get the path waypoints
			waypoints = path:GetWaypoints()

			-- Detect if path becomes blocked
			blockedConnection = path.Blocked:Connect(function(blockedWaypointIndex)
				-- Check if the obstacle is further down the path
				if blockedWaypointIndex >= nextWaypointIndex then
					-- Stop detecting path blockage until path is re-computed
					blockedConnection:Disconnect()
					-- Call function to re-compute new path
					followPath(destination)
				end
			end)

			-- Detect when movement to next waypoint is complete
			if not reachedConnection then
				reachedConnection = humanoid.MoveToFinished:Connect(function(reached)
					if reached and nextWaypointIndex < #waypoints then
						-- Increase waypoint index and move to next waypoint
						nextWaypointIndex += 1
						humanoid:MoveTo(waypoints[nextWaypointIndex].Position)
					else
						reachedConnection:Disconnect()
						blockedConnection:Disconnect()
					end
				end)
			end

			-- Initially move to second waypoint (first waypoint is path start; skip it)
			nextWaypointIndex = 2
			humanoid:MoveTo(waypoints[nextWaypointIndex].Position)
		else
			warn("Path not computed!", errorMessage)
		end
	end

	followPath(TEST_DESTINATION)
	

	

	

		

	


end

This is the free code on the new Waypoint service page.
This is the error I get:
ServerScriptService.NPCModule.basicFunctions:13: attempt to call a nil value

Thanks for your help!

Which line did the error message points to?

Also, you should avoid using Path.Blocked event as it is broken and most scripts doesn’t use this event anymore.

I’ll try this out and mark it as the solution if it works. Thanks!

local humanoid = Char:WaitForChild("Humanoid")

The issue was actually I was doing in another script to fire the module function: BasicFunctions:MoveTo(args) I should of done, BasicFunctions.MoveTo(args)