Hello I am trying to add luck to this weighted luck system.
return {
getRandomIndex = function(playerLuck, chances)
for i, v in ipairs(chances) do
local randomNum = math.random(1, v[2])
if randomNum then
if randomNum == 1 and v[2] > chances[1][2] then
return {
v[1];
v[2];
v[3];
}
end
end
end
return chances[1]
end,
}
So far its properly returning based on chances This is in 1 Million roles
First Is 1 in 3
Second Is 1 in 5
Third Is 1 in 9
How would you add luck to it? I have a number value which is the player luck but I have no idea on how to boost the player chances of getting a “luckier” chance.
You can probably create another RNG between like, half luck and whatever the luck stat is, and add the outcome to the final number if it’s higher than the minimum luck needed to pass.
local luckModifier = math.random(luck * 0.5, luck)
local randomNumModified = randomNum + if luckModifier > "minimum luck" then ("amount to add") else 0
Or maybe make the math.random range between luck and 100 (assuming luck doesn’t cap out at 100. Then maybe 150 or 200? Something higher)
local luckModifier = math.random(luck, 100)
local randomNumModified = randomNum + if luckModifier > "minimum luck" then ("amount to add") else 0
Also lume has a lot of very handy features to it, is 90% compatable with roblox and can teach you some interesting patterns and lua sugar like function chaining.