Function picking more than one random object?

Hello, I’m currently working on a game that needs a rarity system, but I’ve encountered a problem.

Basically to keep it short, the function will find a random rarity, and then find another and another rarity, and the last rarity it picks is the one that the player gets (usually more uncommon rarities)

For example we have the source code right here:

local RS = game. ReplicatedStorage 
local BG - RS. BillboardGui 
local Rarity - BG. Rarity

local multipliersArray - {
    Common = 0.50 
    Uncommon - 0.35, 
    Rare - 0.10, 
    Epic -0.05, 
    Legendary -0.01, 
    Mythic - 0.001
}

local function chooseIndex(multipliersArray)
         local weightedSum = 0 
         for i,v in pairs(multipliersArray) do
             weightedSum += V 
         end 
         local random = Random.new() 
         local rnd - random:Next Number(0, weightedSum)
         for i,v in pairs(multipliersArray) do if rnd <V then
               Rarity.Value = i 
               print(i)
         end
         rnd -= v
   end
end
choose Index(multipliersArray)

unknown

And it will print out:
Screenshot 2022-07-04 9.48.09 AM

But it will only use the last one, as I stated, so it picks Rare, not Uncommon. I only want it to pick once though, so how can I achieve this?

Did you run the screenshot of your code through OCR or something instead of just copy pasting it? Anyways…

Can you describe exactly what you’re trying to achieve? Just choose a value from that table based on their relative probabilities?

Have you tried adding a break there?

         for i,v in pairs(multipliersArray) do if rnd <V then
               Rarity.Value = i 
               print(i)
               break
         end

yeah cause i switched devices

Yup, that’s exactly what I want.

Nope, I’ll try it out later and let you know the results.