This is how I implemented luck in an RNG type game. (This also takes into account a luck value so you can easily implement potions/upgrades into your game)
local random = Random.new()
local ChancesModule = require(SharedModules.ChancesModule)
local function selectRandom(plr)
local lastIndex = 1
for index,value in ChancesModule do
if (random:NextInteger(1,value[2]) / plr.playerValues.Luck.Value) <= 1 and value[2] > ChancesModule[lastIndex][2] then
lastIndex = index
end
end
return lastIndex
end
ChancesModule:
local Chances = {
{"Common", 2, Color3.fromRGB(202, 202, 202), "bad rarity"},
{"Uncommon", 4, Color3.fromRGB(132, 202, 116), "kinda bad"},
{"Rare", 10, Color3.fromRGB(61, 64, 255), "wow so rare"},
{"Epic", 25, Color3.fromRGB(141, 0, 202), "so epic"},
{"Legendary", 50, Color3.fromRGB(255, 213, 0), "legendary????"},
{"Mythical", 100, Color3.fromRGB(110,255,224),"no way its a mythical"},
}
return Chances
If you want any further explanation as to how this works feel free to ask.