Pathfinding not working

I am trying to make a script that moves an NPC to an ore specifically the last ore in the table.
I tried printing in between lines and it seemed to stop working at the for loop. I have tried searching around the Developer Forum for an answer. But couldn’t find one that worked. I have tried to changing the position in case the path was blocked by anything but that didn’t work either.

local availableOre = oreTable[#oreTable]
local PathfindingService = game:GetService("PathfindingService") 
local path = PathfindingService:CreatePath()
local waypoints = path:GetWaypoints()


function moveToOre()
	local worker = availableWorkers[#availableWorkers]

	for i, waypoint in pairs(waypoints) do 
		if waypoint.Action == Enum.PathWaypointAction.Jump then 
			worker.humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
		end

		worker.Humanoid:MoveTo(availableOre.Position + Vector3.new(0,0,-1)) 
		worker.Humanoid.MoveToFinished:Wait()

	end
end


if availableWorkers[#availableWorkers] and oreTable[#oreTable] == nil then
	repeat wait() until availableWorkers and oreTable[#oreTable] ~= nil 
	moveToOre()
else 
	moveToOre()

Could anyone help with this? I haven’t found a solution yet.

Pretty sure the only place you are doing the bottom section is the first time it runs.
It calls the moveToOre() function no matter what, but after that the funcion is only called inside the function.
The function is ending before the bottom if statement.

Also within your moveToOre() function, that is where you need to CreatePath:

function moveToOre()
	local worker = availableWorkers[#availableWorkers]
	local path = pathfinding:CreatePath()
	path:ComputeAsync(worker .HumanoidRootPart.Position, oreTable[#oreTable].Position)

	local waypoints = path:GetWaypoints()
	for i, waypoint in pairs(waypoints) do 
		if waypoint.Action == Enum.PathWaypointAction.Jump then 
			worker.humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
		end

		worker.Humanoid:MoveTo(availableOre.Position + Vector3.new(0,0,-1)) 
		worker.Humanoid.MoveToFinished:Wait()

	end
end

That’s a rough guess. I would test and see if it works.