The only possibility I can think of, is that Path:GetWaypoints
has a new bug that causes it to occasionally return nil
. According to the Documentation,
, even if the path fails to be computed, it shouldn’t return nil
.
Also, in your video, the error says it’s coming from like 364
, but on the latest version of SimplePath
(from March of 2022), the Module is only 350
lines long:
And, for the elseif #self._waypoint == 2 then
code to be reached, you would have to have a non-Humanoid
NPC. Is it? But, these are more secondary questions, not really related to your actual issue.
Anyway, you can report this as a bug. The only way for self._waypoints
to be nil
, would be for Path:GetWaypoints
to return nil
, and there was recently a bug report for PathfindingService
causing a crash, so maybe there have been some internal changes and this new bug slipped through the cracks.
As a workaround, you can add an additional condition to the SimplePath
code, and change this block of code:
--Begin pathfinding
if self._humanoid then
self._humanoid:MoveTo(self._waypoints[self._currentWaypoint].Position)
elseif #self._waypoints == 2 then
self._target = nil
self._visualWaypoints = destroyVisualWaypoints(self._visualWaypoints)
self._events.Reached:Fire(self._agent, self._waypoints[2])
else
self._currentWaypoint = getNonHumanoidWaypoint(self)
moveToFinished(self, true)
end
, to this:
--Begin pathfinding
-- If `_waypoints` is `nil` due to the `Path:GetWaypoints` bug,
if not self._waypoints then
-- , create our own waypoints list directing the NPC
-- to just move in a straight line to their target
self._waypoints = {
PathWaypoint.new(
self._agent.PrimaryPart.Position,
Enum.PathWaypointAction.Walk
),
-- A Jump waypoint to our target position
-- `Enum.PathWaypointAction.Jump` could be changed to
-- `Enum.PathWaypointAction.Walk` if you don't want the
-- agent to jump
PathWaypoint.new(
(typeof(target) == "Vector3" and target) or target.Position),
Enum.PathWaypointAction.Jump
)
}
end
if self._humanoid then
self._humanoid:MoveTo(self._waypoints[self._currentWaypoint].Position)
elseif #self._waypoints == 2 then
self._target = nil
self._visualWaypoints = destroyVisualWaypoints(self._visualWaypoints)
self._events.Reached:Fire(self._agent, self._waypoints[2])
else
self._currentWaypoint = getNonHumanoidWaypoint(self)
moveToFinished(self, true)
end
Check for errors before running, I just wrote this out in the DevForum Reply Editor thing, I didn’t test it out.