Best/most efficient way to handle failed paths, or stop them from failing them in the first place?

I’ve written an AI using pathfinding service which wanders around the map by picking a random position, generating a path and moving to that position, and then repeating. Quite often though it generates points that for whatever reason pathfindingservice can’t find a valid path, to handle this I simply generate a new point and try that one instead. This works fine, but I’ve counted the number of failed and succesful paths and the failed paths are roughly 50% of the total paths I generate, which is obviously very inefficient.

The AI always finds a valid path in the end, but it can take between 5-10 tries in some cases, not ideal.

So is there any way I can reduce the number of paths which fail? For reference this is how I select my points:
targetPos = char.PrimaryPart.Position + Vector3.new(rng:NextInteger(50, 100) * rng:NextInteger(-1, 1), 0, rng:NextInteger(50, 100) * rng:NextInteger(-1, 1))

So it chooses a random x and z value between from -50 → -100 or 50 → 100 away from the character, then generates a Vector3 from these two values (y value is the same as the character’s).

If you’d like the AI to wander around the map in a “random” fashion by picking a point in the near vicinity of its current position you will likely always run into these “failed path” situations. 50% doesn’t sound too terrible actually. If you would like to avoid running into failed paths, you could implement some sort of graph of nodes which you know the AI can pathfind to successfully. At whichever node in the graph the AI is at, you can just choose a random edge to traverse, knowing the pathfinding will not fail on this attempt (you would need to test this beforehand to ensure, but wouldn’t then need to after). Make sure to update the node that the AI is at once it successfully reaches each destination.

I thought of that, but unfortunately it’s unfeasible for the size of the map I’m using. Thanks though.

For anyone with a similar problem, just using humanoid:MoveTo() works nearly as well, you will have to handle the NPC walking into walls sometimes but there are multiple ways you can get around that.