Finding the closest 2 attachment points parented to a rail on touch

Title. As part of my rail-grinding system I want to find the closest 2 attachment nodes when the player touches a rail in order to grind on it. My current system accounts for straight rails with just a starting and ending point, but for nodes with curves or corners, I’d have to remake the script for those. I’m not sure how to go about this though, so any ideas or references would be appreciated.