Help with rarity button

Hello, i am trying to make a rarity button that which you click should roll a rarity with a luck based system, something like SOL’s RNG. I have made the rarities and tried assigning small numbers so that it wouldnt lag when calculating the bigger ones, since it happended before. Here is my script:

local Items = {
	{"Common", 1, LuckMultiplier = 0.25},
	{"Uncommon", 2, LuckMultiplier = 0.0625},
	{"Rare", 3, LuckMultiplier = 0.03125},
	{"Very Rare", 4, LuckMultiplier = 0.015625},
	{"Epic", 5, LuckMultiplier = 0.0078125},
	{"Legendary", 6, LuckMultiplier = 0.00390625},
	{"Mythic", 7, LuckMultiplier = 0.001953125},
	{"Ethereal", 8, LuckMultiplier = 0.0009765625},
	{"Godly", 9, LuckMultiplier = 0.00048828125},
	{"Eternal", 10, LuckMultiplier = 0.000244140625},
	{"Divine", 11, LuckMultiplier = 0.0001220703125},
	{"Insane", 12, LuckMultiplier = 0.00006103515625},
	{"Forsaken", 13, LuckMultiplier = 0.000030517578125},
	{"Life-changing", 14, LuckMultiplier = 0.0000152587890625},
	{"Centurial", 15, LuckMultiplier = 0.00000762939453125},
	{"Godforsaken", 16, LuckMultiplier = 0.000003814697265625},
	{"Forbidden", 17, LuckMultiplier = 0.0000019073486328125},
	{"Theoretical", 18, LuckMultiplier = 0.00000095367431640625},
	{"Immeasurable", 19, LuckMultiplier = 0.000000476837158203125},
	{"Omega", 20, LuckMultiplier = 0.0000002384185791015625},
	{"Supergodly", 21, LuckMultiplier = 0.00000011920928955078125},
	{"Infinite", 22, LuckMultiplier = 0.000000059604644775390625},
	{"Praiseworthy", 23, LuckMultiplier = 0.0000000298023223876953125},
	{"Absolute", 24, LuckMultiplier = 0.00000001490116119384765625},
	{"Zenith", 25, LuckMultiplier = 0.000000007450580596923828125},
	{"Indescribable", 26, LuckMultiplier = 0.0000000037252902984619140625},
	{"Supremiliatic", 27, LuckMultiplier = 0.00000000186264514923095703125},
	{"Universal Manipulating", 28, LuckMultiplier = 0.000000000931322574615478515625},
	{"Absurd", 29, LuckMultiplier = 0.0000000004656612873077392578125},
	{"Alien Limit", 30, LuckMultiplier = 0.00000000023283064365386962890625},
	{"Roller", 31, LuckMultiplier = 0.000000000116415321826934814453125},
	{"Cent-ill", 32, LuckMultiplier = 0.0000000000582076609134674072265625},
	{"Quantum", 33, LuckMultiplier = 0.00000000002910383045673370361328125},
	{"Dope", 34, LuckMultiplier = 0.000000000014551915228366851806640625},
	{"Multiverse-Shattering", 35, LuckMultiplier = 0.0000000000072759576141834259033203125},
	{"Omniverse-Incinerating", 36, LuckMultiplier = 0.00000000000363797880709171295166015625},
	{"Omega-Impossibly Impossible", 37, LuckMultiplier = 0.000000000001818989403545856475830078125},
	{"Omnipotent", 38, LuckMultiplier = 0.0000000000009094947017729282379150390625},
}

local TotalWeight = 0

for _, ItemData in pairs(Items) do
	TotalWeight = TotalWeight + ItemData[2]
end

local baseLuck = 1 
local luckDecreaseAmount = 0.00000000000000994947017729282379150390625 

local function chooseRandomItem()
	local Chance = math.random(1, TotalWeight)
	local Counter = 0
	for _, ItemData in pairs(Items) do
		Counter = Counter + ItemData[2]
		if Chance <= Counter then
			return ItemData[1]
		end
	end
end

local button = script.Parent 

button.MouseButton1Click:Connect(function()
	local selectedItem = chooseRandomItem()
	print("Selected Item:", selectedItem)

	baseLuck = math.max(0.00000000000000994947017729282379150390625, baseLuck - luckDecreaseAmount) 
end)

Its nothing really complicated but I cant get my head around it, any help would be appreciated.
The problem is that its choosing the rarities from the middle of the list and isnt really coordinated.

These lines should be ItemData[2][3] if you’re trying to get the value of LuckMultiplier. I’m not sure if that has anything to do with it, but it’s worth looking into if that’s the case.

3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.