To start, I’m pretty bad at math until something is explained to me, so, if anyone is willing to help with my problem I’d also really appreciate an explanation alongside it. I’ve made a lot of weighted tables for drop systems and such but never have I been able to factor in a luck variable that works how other games seem to achieve it.
Right now, I’m trying another type of “loot-table” I guess, similar to how rng games present it but more than ever I’m struggling to add luck into the equation. Here’s my test without any attempt of adding luck:
--//Services
--\\
--//Modules
--\\
--//Const Variables
local random = Random.new(tick())
local rolls = {
{name = "1 in 1", rarity = 1};
{name = "1 in 2", rarity = 2};
{name = "1 in 4", rarity = 4};
{name = "1 in 8", rarity = 8};
{name = "1 in 16", rarity = 16};
{name = "1 in 32", rarity = 32};
{name = "1 in 64", rarity = 64};
{name = "1 in 128", rarity = 128};
{name = "1 in 256", rarity = 256};
{name = "1 in 512", rarity = 512};
{name = "1 in 1024", rarity = 1024};
{name = "1 in 2048", rarity = 2048};
{name = "1 in 4096", rarity = 4096};
{name = "1 in 8192", rarity = 8192};
{name = "1 in 16384", rarity = 16384};
{name = "1 in 32768", rarity = 32768};
{name = "1 in 65536", rarity = 65536};
{name = "1 in 131072", rarity = 131072};
}
--\\
--//Variables
local rarestRoll = 0
--\\
--//Other
--\\
--//Functions
script.Parent.MouseButton1Click:Connect(function()
local total = 0
for _, roll in ipairs(rolls) do
total += 1 / roll.rarity
end
local randomNumber = random:NextNumber()
local accumulatedChance = 0
for i, roll in ipairs(rolls) do
accumulatedChance = accumulatedChance + (1 / roll.rarity) / total
if randomNumber <= accumulatedChance then
if roll.rarity > rarestRoll then
rarestRoll = roll.rarity
end
print(string.format("Rolled: %s | Highest Roll: %i", roll.name, rarestRoll))
return
end
end
end)
--\\
I have tried a few methods of adding in luck, some appear to work but I’m getting 1 in 1s along with 1 in 8ks regularly which isn’t aligning with what I’d want. I’ll present one method I’ve tried with adding luck:
--//Services
--\\
--//Modules
--\\
--//Const Variables
local random = Random.new(tick())
local rolls = {
{name = "1 in 1", rarity = 1};
{name = "1 in 2", rarity = 2};
{name = "1 in 4", rarity = 4};
{name = "1 in 8", rarity = 8};
{name = "1 in 16", rarity = 16};
{name = "1 in 32", rarity = 32};
{name = "1 in 64", rarity = 64};
{name = "1 in 128", rarity = 128};
{name = "1 in 256", rarity = 256};
{name = "1 in 512", rarity = 512};
{name = "1 in 1024", rarity = 1024};
{name = "1 in 2048", rarity = 2048};
{name = "1 in 4096", rarity = 4096};
{name = "1 in 8192", rarity = 8192};
{name = "1 in 16384", rarity = 16384};
{name = "1 in 32768", rarity = 32768};
{name = "1 in 65536", rarity = 65536};
{name = "1 in 131072", rarity = 131072};
}
--\\
--//Variables
local rarestRoll = 0
--\\
--//Other
--\\
--//Functions
script.Parent.MouseButton1Click:Connect(function()
local luck = 1
local total = 0
for _, roll in ipairs(rolls) do
total += 1 / (roll.rarity / luck)
end
local randomNumber = random:NextNumber()
local accumulatedChance = 0
for i, roll in ipairs(rolls) do
accumulatedChance = accumulatedChance + (1 / (roll.rarity / luck)) / total
if randomNumber <= accumulatedChance then
if roll.rarity > rarestRoll then
rarestRoll = roll.rarity
end
print(string.format("Rolled: %s | Highest Roll: %i", roll.name, rarestRoll))
return
end
end
end)
--\\
I’m aware the issue with this is I’m dividing all the chances equally so no matter what I set that “luck” value to it doesn’t technically change any odds at all.
Any help whatsoever getting me in the right direction I’d really appreciate, I’ve spent time going through multiple topics in the forums but the answers never really clicked with me in a way I could understand; which is why I’ve made some test code so hopefully any answer is more understandable to me.