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!