So I’m trying to make the table pick a random item from the talbe, but it doesn’t work because I have 2 values and it should only pick the name of the color.
local colors = {}
for _, rarity in pairs(rarityTable) do
for name, _ in pairs(rarity) do table.insert(colors, name) end
end
local color = colors[math.random(#colors)]
print(color)
I guess you’re trying to get a random element in the rarityTable?
Since the ‘table’ is a table containing string indexes, it is essentially a dictionary.
So, in other words, you’re trying to get a random element in a dictionary.
You could have another table which stores the indexes.
local rarityIndexes = {'Common'}
local rarityColorIndexes = {
{'White'},
}
local randomRarity = rarityIndexes[math.random(1, #rarityIndexes)]
local randomColorFromRarity = rarityColorIndexes[table.find(rarityIndexes, randomRarity)]