How will I go about making a chance system that supports Luck Boosts?

I’ve been making an RNG game similar to Sol’s RNG. I got the basic system working, but I don’t know how to make it pick a random rarity with a luck boost system.
When replying, please provide explanations and/or script examples.

My rarities are based on NumberValues, stored in a folder (RaritiesFolder).
If you have any questions, please ask it.

4 Likes

Let’s say this is your luck system

Local LuckMultiplier = 1
Local EggPicker = math.random(1, 300 / LuckMultiplier)
If EggPicker == 299 then
print("unboxed dragon egg")
end

Here in this script our dragon egg chance is 1 in 300 but as you can see we have a LuckMultiplier variable which we divide our chance by. In this case it would be 300. If our Multiplier was set to 2 we would divide 300 by two and get 150. So our chances would be twice as high.

1 Like

To make this easier, theres 46 rarities that are inbetween the chances, 2 and 25k

You could just loop through all your Numbervalues for the rarities and divide them by 2 to give double the luck.

If you divide all of them by 2 they would all still have the same chance as before. You would probably have to make a formula that makes it so the stuff with higher chances, so its not as rare, gets a lower chance, meanwhile the stuff with a lower chance, so rarer, get a higher chance.

That is pretty much EXACTLY what I want.

Maybe something like:
f(x) = (x-a)^3

Could you elaborate what f=?, x=?, and a=?
Plus, I have not learned that formula in school yet, I’m in 6th right now…

Depends on how far you wanna go about it

math
This is for example what this would look like: f(x) = (x-3)^3

In terms of a roblox function it would be:

local maxChance = 42412 -- Whatever the highest chance in your system is
function calculateMultiplier(chance)
return (chance - maxChance/2) ^ 3
end

In the graph, X is the Chance you put into it, and Y is the multiplier you get out of it.

So could you explain what (chance - maxChance/2) ^ 3 would be if chance = 77
and maxChance = 25000? Maybe even explain the formula a lot more so I could learn more before I start Algebra 1 next year?

LOL. I barely understand math myself.

I’m not sure what you’ve had in math until now, but I the foruma is basically: x ^ 3. If you have had x^2 before, that would be positive on both sides even if you put a negative number as x since -1 * -1 = 1 for example, they basically cancel each other out. But if you have ^ 3 its: - 1 * - 1 (which is 1) * -1 = - 1, thats why its negative on the Y axis as well. On the other hand if you take another even number, 4 for example, as the exponent, it would be positive on both sides again, just more stretched out and stuff, 5 would be the same as 3 just more stretched out.

I gotta finish my food before I can get to making this formula, so I might take a bit.

Me in the back after reading the last line while searching through dev forum for a total of 9 hrs on this system: screams in agony

Do I use the function to find the Calculated Chance on each Roll?

Hey, just came back and thought about it, I was totally dumb for thinking of using ^3 when the increase in the multiplier can just be linear. The Formula is really simple
f(x) = multiplier/max * chance
Basically, you’d be able to do:

function calculateChanceMultiplier(chance, maxMultiplier)
return multiplier/maxChance * chance
end

That’s that.

Now, you mentioned having 46 rarities. I’d recommend storing them in a module script in a table sort of like

module = {
Epic = 20,
Legendary = 10
}
return module

But I’m not sure if that is actually important in your case. Just keep in the back of your mind.

I’ve never implemented a system like this, but I guess when you roll and I don’t know what yours works like, but upon rolling, you probably get a table of all chances, then you use math.random or whatever and get one of them depending on the math.random return? In that case, whenever you roll and get the table of chances, just multiply the chance by the chance multiplier.

Hope this works and helps!

Wait, If I multiply the chance, doesn’t that make it more rare?

I worked on a small start of the RandomHandler script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local StatsFolder = ReplicatedStorage:WaitForChild("Stats")
local EventsFolder = ReplicatedStorage:WaitForChild("Events")

local activateRoll = EventsFolder:WaitForChild("ActivateRoll")
local messages = EventsFolder:WaitForChild("Messages")

local totalStats = StatsFolder:GetChildren()

local function SelectRarity(player)
	
	local luckboost = player.Boosts.Luck.Value
	
	--randomizer code
	
end

activateRoll.OnServerInvoke = function(player)
	
	player.leaderstats.Rolls.Value += 1
	local t = {}
	
	for i=1, workspace.GameInfo.RollAmount.Value - 1 do
		
		table.insert(t, StatsFolder[SelectRarity(player)])
		
	end
	
	local s = StatsFolder[SelectRarity(player)]
	
	if s.Value >= 750 then
		
		messages:FireAllClients(player.Name .. " has gotten " .. s.Name .. "! (1/" .. s.Value .. ")")
		
	end
	
	table.insert(t, s)
	
	print(s)
	
	return t
	
end
1 Like

It depens on what your system works like… If so, I think this should fix it:

function calculateChanceMultiplier(chance, maxMultiplier)
  return -multiplier/maxChance * chance + maxChance
end

Seems fine, if you need a reference on how to make a weight based luck system there is this post which is quite helpful:

I can use that, but how would I make the NumberRange fit the numbervalue? I could give you permissions to the game if you’d like.

No need, when you :GetChildren() you can sort that table to go from largest to smallest, that way you don’t need to define a maximum, you just check if the rand is higher than the value. You can use table.sort for this.

local rarities= ...:GetChildren()
table.sort(rarities, function(a, b)
  return a.Value > b.Value
end

I think that should work.