Is it possible to sort string values by their name?
local stationName = routeFolder.Stations:GetChildren() for i = 1, #stationName do --in here is a script that basically generates a timetable from the children of the Stations folder end
The reason I can't use the values in any order is because on the return journey the stations list needs to be read in reverse order (from 7 to 1) meaning I would need a way of sorting them by reverse alphabetical order too. I know you can sort tables but is there something similar I could use to sort this? Thanks!
If you are only using numbers as station names you can convert the name into a number and then just compare greater and less to determine the order.
local Stations = {} -- Define table to insert stations into. for i,v in pairs(workspace.Stations:GetChildren()) do -- Change "workspace.Stations" to wherever your stations are. table.insert(Stations,tonumber(v.Name)) -- Convert the station name into a number, and add it to the Stations table. end table.sort(Stations, function(a,b) -- Function to sort the table. return a<b -- If a is less than b, then put a below b. If you want to reverse the order change a<b to a>b end) for i,v in pairs(Stations) do -- Iterate through the stations table print(v) -- Print the stations in order. end --[[ Basic Rundown: This code creates a table, adds all of the stations into the table, and then sorts the table from least to greatest (or if you change to A>B, then from greatest to least) You can then iterate through the Stations table to do what you need to do. ]]