Is the best way to do this?

So I made this system like in All Star Tower Defense where you have a roster that resets every hour. You get a new set of towers, one from each rarity. Heres how I did it:

local towers = require(replicatedStorage:WaitForChild("TowerShop"))
local towerRoster = require(serverscriptService:WaitForChild("TowerRoster"))
local function restockRoster()
	for i, rarityTable in pairs(towers) do
		local keys = {}
		for key, _ in pairs(rarityTable) do
			table.insert(keys, key)
		end

		if #keys == 1 then
			local onlyKey = keys[1]
			return rarityTable[onlyKey]
		end

		local position = Random.new():NextInteger(1, #keys)
		local key = keys[position]

		table.insert(towerRoster,rarityTable[key])
		
	end
end

This is what the “TowerShop” module looks like:

local TowerShop = {
	
		["Common"] = {
			["CCTV-Man"] = {
				["Name"] = "CCTV-Man",
			["ImageAsset"] = "http://www.roblox.com/asset/?id=13749054780",
			["Rarity"] = "Common"

			},
			["Speakerman"] = {
				["Name"] = "Speakerman",
			["ImageAsset"] = 'http://www.roblox.com/asset/?id=13749300689',
			["Rarity"] = "Common"

			},
			["TV-Man"] = {
				["Name"] = "TV-Man",
				["ImageAsset"] = "http://www.roblox.com/asset/?id=13767180458",
				["Rarity"] = "Common"
			},
	},

And the TowerRoster module is just a blank dictionary. I just want to know if this is the best way to approach this goal? Any feedback is appreciated, thanks!

Looks good, two things though.

Why do you have to include a key in each dictionary called “Rarity” when your main one is already called the rarity?

You can name your keys like this if you feel it’s more readable (only if the keys do not have special characters):

local TowerShop = {
	Common = {
		Speakerman = {
			Name = "Speakerman",
			ImageAsset = 'http://www.roblox.com/asset/?id=13749300689',
			Rarity = "Common"
		},
	},
}

Yeah the reason why I do that is because its kinda weird referencing a “parent” of something in a dictionary so I just do thats so its a bit easier