Accurate Luck Boost?

Hey, i like to use weighted chance systems Like:

local Rarities = { 
Common = 1/2,
Uncommon = 1/5,
Rare = 1/12,
},

i wonder if theres a way how to make a chance system with accurate boosts?.
if anyone knows how, please give me some script examples. ty

The way you can do it is by having a modifier used during your rarity check

function checkPull(boostModifier: number)
     --setting the PRNG seed based on the server time to guarantee a more random assortment
     math.randomseed(workspace:GetServerTimeNow())
     --boostModifier is a scalar value, so we multiply the outcome
     local rng = math.clamp(1 - (math.random() * boostModifier), 0, 1)
     for i,v in Rarities do
          if rng < v then return tostring(i) end
     end
     return nil
end

The reason you want to do something like this instead of adding the modifier to the result is so that you aren’t cutting off a section of the RNG table

For example: Say your player buys a 30% luck boost, if you were to add the modifier in your player would only be able to roll a minimum of 30/100, meaning that they’re guaranteed 80% of the time to get an uncommon or better which depending on your luck table may be a problem

Now let’s use that 30% luck boost but with a multiplication system. Well a 30% increase in luck would mean multiplying your rng roll by x1.3,

Here’s an example of how this can impact your rng roll using a 30% RNG boost

--No Modifier: 0.40009932572819973  -  AKA getting a common drop
--With Modifier: 0.22012912344665958 - AKA getting an uncommon drop
1 Like

Hey, this doesnt rly work. it returns nil kinda often if i try with like 5x luck boost or something.
i appreciate your answer.
i think it is not working properly because of the math.random() * boostmodifier. because if its like 3 0.5 then 1- 1.5 = -0.5

maybe could you fix the code, so its working ? :slight_smile:

My code works fine.

The reason it returns nil is because when the rng rolls a 0 there is no option with a 0% chance of success, to solve this simply have the default value for no other matches be the highest tier return.

Also the boost modifier math is correct, because it’s always clamped between 0 and 1