Here's what I have made right now:

local Items = {
	["Blue"] = 500; -- common
	["Orange"] = 200; -- uncommon
	["Red"] = 50; -- rare
	["Purple"] = 1; -- legendary
};

local Spawns = {};

local function setSpawns()
	for i = 1,500 do
		for item,rarity in pairs(Items) do
			if (Items[item] > 0) then
				table.insert(Spawns,item);
				Items[item] = Items[item] - 1;
			end;
		end;
	end;
end;

setSpawns();

local function spawnItem()
	local Item = Spawns[math.random(1,#Spawns)];
	print(Item);
end;

while (wait(1)) do
	spawnItem();
end;

I'm not sure that this is the most accurate/efficient way for a rarity system though. Any help or information would be much appreciated.

3 comments

0

I believe that what you have is pretty fine. try measuring how much time it takes. but if you really want something you can try not using tables because I remember hearing that they are resource intensive especially when you have 500 indexes.

0

yeah what you have is fine

0

Thanks