Restockable shop?

So I have this summoning system where you just get a random tower. I have have the common, rare and legendary in a dictionary. However, all towers in all rarities are available and I want to make it so every hour it chooses one random tower from each rarity and stocks them so only those 3 are available then a new hour and another 3 are available, one from each rarity. How can I go about doing this?

1 Like

For more context, this is what the summons system looks like at the moment

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 heres an example of the TowerShop module table:

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"
			},
	},

You can use DateTime to set up a proper calender.

Im not too worried about the every hour part since I already know how to do that. I’m just not sure how I could select 1 from each rarity and make them the only ones obtainable until of course another hour passes.

You break down the day into hours. For example, if it is 12:XXpm, first rarity should appear, 1:XXpm second rarity, and so on.

I didn’t really mean it like one rarity I meant all. If you’ve ever played a game like All Star Tower Defense, you have a roster with the 3 star character, 4 star and so on and it changes every now and then so a different roster is available. I’m already very familiar with how to work with time but I just don’t know how to switch up the rosters like that and putting up a new set of available ones.