I’m trying to make a summon system where you basically pay and get something random. I made this script where it chooses a random rarity then something random in that rarity.
local towers = require(replicatedStorage:WaitForChild("TowerShop"))
local function getRarity()
local random = math.random(1,100)
if random == 1 then
return "Legendary"
elseif random > 1 and random < 31 then
return "Rare"
elseif random > 31 then
return "Common"
end
end
replicatedStorage.SummonTower.OnServerInvoke = function(player)
if player then
local chosenRarity = getRarity()
local rarityTable = towers[chosenRarity]
print(rarityTable)
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]
print(rarityTable[key])
return rarityTable[key]
end
end
And this is what the table looks like
["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"
},
},
This works fine but I want it so every hour it takes one random tower from each rarity and basically supplies them. So each hour, a new set of towers, one from each rarity will be in stock and possible to get. I’m not really sure how to go about this so any help is appreciated, thanks!