Can I suggest just doing a print(waypoints) after you have defined. Just because you have numbered them does not mean that they will appear in numerical order in the table. If you want them to be defined numerically, I’d recommend pre-populating the table:
local waypoints = {bruh.Waypoints.1, bruh.Waypoints.2, bruh.Waypoints.3, bruh.Waypoints.4}
That might work, but no guarantee that when you run through them as ipairs they will not get messed up again, so the other alternative would be to define them with an index:
Is that 2 consecutive tests? If it is then see my first answer. When you do the GetChildren, they are not always guaranteed to be in the order in which they appear in the Explorer pane in Sutudio.
I’d suggest using the second method of defining the index for each waypoint and iterating through them that way.
OK, you could use tonumber() to convert the part name into an numerical value, then manually insert them to the table at the correct index position, obviously including an edge case check for “end”.
It’s late and I would make a mess of that at the moment. Essentially, you need multiple tables:
local waypoints = bruh.Waypoints:GetChildren() -- The waypoints
local waypointNames = {} --The numerical value of the waypoints name
-- Build WaypointName & Index tables
for index, part in ipairs(waypoints) do
table.insert(waypointNames , tonumber(part.Name))
end
-- Sort table by Waypoint Name value
table.sort(waypointNames )
-- Iterate thru waypoints now in numerical part name order
for index, part in ipairs(waypointNames ) do
local vpos = bruh.Waypoints:FindFirstChild(part).Position + Vector3.new(0, 2.93, 0) -- your parts position
-- the rest of your code checks
end
I think that will work. I went thru numerous revisions and the above seems quick and dirty