Pathfinding wrong path

Hi everyone! Today i was training on script and i’ve tried to make a simple pathfinder to go on a seat choosing them randomly, the issue is that for some reasons the pathfinding overlaps with the seats making the npc go from all seats before reaching the one he should go

for example, the seat is N3, he goes over the 1,2, and then the N3
if is N4 he goes over the 3 and then the N4

Here is a screen of what happens

any ideas?

NOTE: Making the seats more distant is possible and fixes the problem but i want to keep them on the grid that will be used in future

You could perhaps increase the NPC’s distance from chairs.

I think they are around 100 studs or a bit less away from them

From what I understand, you’re essentially having an error, where the ray-cast fires, but builds a path overlapping all the seats, is this correct? And you want the ray-cast to lead you to the seat its raycasting to, but for some odd reason, it’s building around all the seats combined.

Here are some solutions that come to mind if I was experiencing this:

1.) Perhaps you don’t need to ray-cast to the seat. If there are no obstacles, instead… why not use something like MoveTo()? And if there IS something, why not just ray-cast from the characters point relative to the part it needs go to? That way, if there is a part, then instead ray-cast.
2.) This can be tied into solution #1. Make the NPC jump until it’s in the seat its ray-casting to, so maybe make an attribute listing what part it’s going to, and when it sits, compare if that seat is equal to the part its pathfinding to, and jump if its not the seat it’s going to. (Make sure it’s an Object Value, that way the names don’t particularly matter / you don’t need to insert any unnecessary values classifying them. :smiley:)

If you do plan on using solution 1, I’d also look into the dot product to compare two different directions of unit vectors. (Basically, making FOV! A range in which we would compare when figuring out if we should raycast, so if object is in sight, and there are no parts in front of it, then you don’t need to raycast, else if there is a part in front of it and it’s in the fov / not, then raycast!)

Actually i’m using this script with only the added

Destination = math.random(1,#seats)

I don’t understand how this snippet of code stops you from doing what I recommended above?

Nvm i’ve readed the answer wrong, Aldo i’ve found a solution, for some reason instead of waypoint loop if changed to MoveTo only (it was in the code before but was Looped to see the dots) the path fixes