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.
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.
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.
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?
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.
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
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.
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
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