Basic RNG + Luck system

It’s handled via client for now so I visualize the items being given. So ignore that part. Besides that, how does everything look. I’ve added the luck measurement that as it’s increased the lower rarities are ignored and the higher ones have better odds. With luck being x2000 you will start to get Epics way more as a common item.

local function roll()
	local luck = script.Luck.Value
	local results = {}

	for itemName, chance in pairs(Items) do
		local effectiveChance = math.max(1, math.floor(chance / math.sqrt(luck)))
		if math.random(1, effectiveChance) == 1 then
			table.insert(results, itemName)
		end
	end

	-- pick the rarest success (highest number)
	if #results > 0 then
		local chosen = results[1]

		for _, item in ipairs(results) do
			if Items[item] > Items[chosen] then
				chosen = item
			end
		end

		updateUI(chosen)
	else
		table.insert(results, "Common")
		updateUI("Common")
	end
end

this is the basic table I use for now…

local Items = {
	["Common"] = 2,
	["Uncommon"] = 3,
	["Rare"] = 10,
	["Epic"] = 34,
	["Legendary"] = 70,
	["Mythic"] = 100,
	["Secret"] = 250,
	["Exclusive"] = 300,
	["Godly"] = 500
}
2 Likes

math.random is rather noisy, so I would consider the Random class with a formula of your choosing for its seed.
I ultimately recommend using this for calculating the return:

5 Likes