I think you are confused on the sorting order of different types of tables.
In Luau, there are two types of tables, mainly arrays and dictionaries. Arrays, like what @NyrionDev has said, are order-specific, meaning each element in this table type are fixed at specific locations. When you iterate this table type, it always returns the element in th order in which they are defined in the table. For instance, iterating a table like so:
local t ={"Memes", "Roblox", "Spaghetti", "Dr. Dre"}
should return "Memes", followed by "Roblox" and so on.
Dictionaries, on the other hand, are key-specific, meaning each element can only be indexed or represented by a key in terms of their position in the table. Since it is not order-specific, the iterator function which iterates this table will return key-value pairs in random orders. For instance, iterating a table as shown below
local t = {
Memes = "Roblox",
Spaghetti = "Dr. Dre",
Death = "Ooops",
}
might NOT necessarily return the key-value pairs in the order which you specified them. In other words, the first key-value pair you get might not necessarily be “Memes” and “Roblox”, instead it could be the other 2 key-value pairs.
So to answer your question, I suggeset that for each value of a key, you make another table, and in that table include the rarirty property along with other stuff you want to be added. Then when you want to find the value from the rarest to the most common, compare each iterated rarity with the previous iterated rarity.
local t = {
Example9 = {
rarity = 20,
...
},
Example2 = {
rarity = 1,
...
},
...
}