Question: What judges what direction the ray will be shooting?

Also, could you solve this another way, let’s say using magnitude by looping through the various nodes and attempting to find the closest one? Each node could be given a count of connections it needs in order to properly handle junctions. If tracks will be running parallel to each other very closely you could also give each node a sort of TrackID so it knows which ones to attach to and which ones to ignore the other nodes?

Would you want to give this a try?
local hyp=i.Size.X/2
local o = Vector3.new(hyp* math.sin(math.rad(i.Orientation.Y)),0,hyp* math.cos(math.rad(i.Orientation.Y))).unit*100

You could then follow what DJX_D was talking about

and use FindPartOnRayWithWhitelist and only include the nodes in the whitelistDescendantsTable argument. I assume the LookVector, RightVector, or UpVector are always pointing near to the next node.

sorry, I left out a part that defined hyp,
local hyp=i.Size.X/2
local o = Vector3.new(hyp math.sin(math.rad(i.Orientation.Y)),0,hyp math.cos(math.rad(i.Orientation.Y))).unit*100

hmm, some multiplies didn’t get copied over. Anyway try now, I hope this works. The *100 at the end is the magnitude of the vector. But, I myself don’t know a lot about rays, I was very interested though.

yeah the ‘*’ are being formatted out here, if it doesn’t get copied over, put a multiply between each hype and math operation and at the end before the 100.

local hyp=i.Size.X/2
local o = Vector3.new(hyp * math.sin(math.rad(i.Orientation.Y)),0,hyp * math.cos(math.rad(i.Orientation.Y))).unit * 100

Be careful using the Raycast method though, if certain turns are too sharp you won’t get the next node. You can also get weird situations depending on how your nodes were placed:

They both appear to be in the same direction, but the LookVector tells otherwise. If this is an issue, this can be solved by just testing both -LookVector and LookVector and remove ones from the whitelistDescendantsTable as you go through them.

NOTE: I assume that your nodes are aligned ONLY along one vector in this case, the LookVector, if not you’ll have to test RightVector, LookVector, -LookVector, -RightVector, and maybe even UpVector, -UpVector.