-- Get the valid destinations by checking their name for the string "Destination " (with a space at the end).

for index, value in pairs(mainFolder:GetChildren()) do
	local valueName = value.Name
	if string.match(valueName, "Destination ") then
		table.insert(destinationList, valueName)
	end
end

local sortedList = {}
repeat -- Sort the list
	local lowestValue = {nil, math.huge}
	-- Table describing the index of the destination of the lowest value, followed by its value.
	for index, value in pairs(destinationList) do
		local nameSplit = string.split(destinationList[index], " ") -- Split the name to isolate its destination number
		local stringToNumber = tonumber(nameSplit[2]) -- Convert the destination number to an actual number
		if stringToNumber < lowestValue[2] then
			lowestValue = {index, stringToNumber} -- Overwrite the lowestValue table with the new lowest value.
		end
	end
	table.insert(sortedList, destinationList[lowestValue[1]]) -- Insert the lowest value into the sorted list
	destinationList[lowestValue[1]] = "Destination 999999" -- Don't remove the lowest value because it will end the loop early.
until #sortedList == #destinationList -- Repeat until the sorted list has all the destinations.
