RNG Roll only getting 2 rarities

So I have 5 rarities and my script is only getting three. (Common, and Grand and Illegal) It also seems it’s only getting a select few materials. (I checked the table, and all possible materials are inside there as well.)

Here’s my code. Also, yes. I tried that weighted roll system. It did the same.

	local wkndm = 1 --weekend multiplier
	if os.date("!*t").wday == 5 or os.date("*t").wday == 6 or os.date("*t").wday == 7 then wkndm = 2 end --Weekend multiplier lolololol, uses UTC time so people dont glitch this
	local Rarities = {
		[1] = 55,
		[2] = 40,
		[3] = 15*wkndm,
		[4] = 10*wkndm,
		[5] = 2*wkndm
	}
	
	local prizes = {}
	--adds all possible materials to the prizes table
	local MaxTier = 5
	local CurrentTierLoader = 1
	repeat
		local Extract = Materials:FindFirstChild("Tier"..CurrentTierLoader)
		if Extract then		
			for i, Item in Extract:GetChildren() do				
				task.wait()
				if Item:IsA("Folder") then
					local ShopData = require(Item:WaitForChild("MaterialShopData"))
					prizes[i] = {
						["Name"] = Item.Name,
						["Rarity"] = Rarities[ShopData.Tier]
					}
				end
			end
		end
		CurrentTierLoader += 1
	until CurrentTierLoader > MaxTier
	
	local totalChance = 0
	for _, entry in ipairs(prizes) do
		totalChance = totalChance + entry.Rarity
	end

	local randomChance = math.random(1, totalChance)
	local cumulativeChance = 0

	for _, entry in ipairs(prizes) do
		cumulativeChance = cumulativeChance + entry.Rarity
		if randomChance <= cumulativeChance then
			print("you won " .. entry.Name)
		end
	end

So the script just seems to completely ignore the “Rare” and “Unreal” rarity. I’ve been spamming console and haven’t gotten a single rare or unreal item.

1 Like

What is totalChance equal to? Print that and show the output

Could you also print the prizes table?

Number, Name, Rarity

I seemed to have fixed it.

prizes[i] = {
						["Name"] = Item.Name,
						["Rarity"] = Rarities[ShopData.Tier]
					}

I changed it to:

prizes[#prizes+1] = {
						["Name"] = Item.Name,
						["Rarity"] = Rarities[ShopData.Tier]
					}
1 Like

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