When making a path with PathfindingService, GetWaypoints is always returning nil. Here is the code:
function module.WalkToPoint(humanoid, endPos)
local startPos = humanoid.Parent.Torso.Position
local path = PathfindingService:CreatePath()
path:ComputeAsync(startPos, endPos)
local waypoints = path:GetWaypoints()
if path.Status ~= Enum.PathStatus.Success then print("failed") end
for i, waypoint in pairs(waypoints) do
local part = Instance.new("Part")
part.Shape = Enum.PartType.Ball
part.Material = Enum.Material.Neon
part.Color = Color3.new(1, 1, 1)
part.Size = Vector3.one
part.Anchored = true
part.CanCollide = false
part.Name = "WAYPOINT!"
part.Parent = workspace
if waypoint.Action == Enum.PathWaypointAction.Jump then
humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end
humanoid:MoveTo(waypoint.Position)
humanoid.MoveToFinished:Wait(2)
end
humanoid:MoveTo(endPos)
end
Another user said that this could be from parts which are really far away: :GetWaypoints returning nil (Pathfinding) - #4 by bongusbingis
I believe this is the cause because I have islands which are spread out over about 25,000 studs. If this is the cause, is there any way to fix it? If not, is there something else wrong with my script which would prevent the character from walking? The status prints Enum.PathStatus.NoPath