Hello! How would I add luck in this rarity script using ternary operations? Do I have to manually do it for each line for example:

I don’t even know if this even works. However, I want it to be automated, and not manually added.

Epic = 0.8 - (if MPS:UserOwnsGamePassAsync(Player.UserId, DoubleLuck) then 0.4 else 0.8), -- 20% chance/ with luck it's 40%

local MPS = game:GetService("MarketplaceService")
local DoubleLuck = 775875234
local Chance = {}
local Rarities = {
Common = 0, -- 60% chance
Rare = 0.6, -- 40% chance
Epic = 0.8, -- 20% chance
Legendary = .9, -- 10% chance
Mythic = 0.99, -- 1% chance
Unique = 0.993,-- 0.7% chance
-- Ultra = 0.995, -- 0.5% chance
-- Insane = 0.999, -- 0.1% chance
-- Arcane = 0.9991, -- 0.09% chance
-- Divine = 0.9995, -- 0.05% chance
-- Demonic = 0.997, -- 0.03% chance
-- Angelic = 0.999, -- 0.01% chance
-- Godly = 0.9991, -- 0.009% chance
-- Unfathomable = 0.9993, -- 0.007% chance
}
function Chance.PickRarity()
local Index = math.random()
local LowestRarity = "Common" -- Basically, the lowest the rarity can go
for RarityName, Value in pairs(Rarities) do -- just getting the rarities
if Index >= Value and Value >= Rarities[LowestRarity] then -- Check if "value (Rarity)" is in the same range of math.random(), and checks if value is greater than "Common"
LowestRarity = RarityName
end
end
return LowestRarity
end
return Chance

your luck is weird
0 ~= 60% → 0 = 0%
0.6 ~= 40% → 0.6 = 60%
maybe you forgot to update your comments

for Rarity, Chance in Rarities do
Rarities[Rarity] -= MPS:UserOwnsGamePassAsync(Player.UserId, DoubleLuck) and (Chance / 2) or 0
end
--[[
Player with double luck:
Common = 0;
Rare = 0.3;
Epic = 0.4;
]]
--[[
Player with standard luck:
Common = 0;
Rare = 0.6;
Epic = 0.8;
]]

like this?
also it’s not python, you don’t need the if statement

-- If someone else doesn't understand how '(v = a and b or c)' works
local BonesIsUseless = {}
local BonesIsRich = false
-- the last "and" is 'do'; and the last "or" is 'otherwise'
-- (If this) and (do this) or this
-- If this, do this, otherwise this
-- If bones is rich, do money = 99999 otherise money = 0
BonesIsUseless.Money = BonesIsRich and 99999 or 0
-- If bones is rich and 1 + 2 = 3, do money = 99999 otherwise money = 0
BonesIsUseless.Money = (BonesIsRich and 1 + 2 == 3) and 99999 or 0
print(BonesIsUseless.Money) --> 0

Ik lol, but that’s how the luck works. Basically 0 is the standard 60% so now when using decimals, 0.6 would be 40% because .6 + .4 = 1. That’s how this luck works. I’ll test this script out! Thanks

local Player = game:GetService("Players").LocalPlayer
local MPS = game:GetService("MarketplaceService")
local DoubleLuck = 775875234
local Chance = {}
local Rarities = {
Common = 0, -- 60% chance
Rare = 0.6, -- 40% chance
Epic = 0.8, -- 20%
Legendary = .9, -- 10% chance
Mythic = 0.99, -- 1% chance
Unique = 0.993,-- 0.7% chance
-- Ultra = 0.995, -- 0.5% chance
-- Insane = 0.999, -- 0.1% chance
-- Arcane = 0.9991, -- 0.09% chance
-- Divine = 0.9995, -- 0.05% chance
-- Demonic = 0.997, -- 0.03% chance
-- Angelic = 0.999, -- 0.01% chance
-- Godly = 0.9991, -- 0.009% chance
-- Unfathomable = 0.9993, -- 0.007% chance
}
for Rarity, Chance in Rarities do
Rarities[Rarity] -= MPS:UserOwnsGamePassAsync(Player.UserId, DoubleLuck) and (Chance / 2) or 0
end
function Chance.PickRarity()
local Index = math.random()
local LowestRarity = "Common" -- Basically, the lowest the rarity can go
for RarityName, Value in pairs(Rarities) do -- just getting the rarities
if Index >= Value and Value >= Rarities[LowestRarity] then -- Check if "value (Rarity)" is in the same range of math.random(), and checks if value is greater than "Common"
LowestRarity = RarityName
end
end
return LowestRarity
end
return Chance

It would update every single value in the table if they own luck? Would it work even with the weird decimals such as 0.99, 0.993, etc?

This solution works but it made it overpowered so basically unique becomes a ~60% luck because 0.4965 – 60.145%. I had to resort with luck boost such as +10 so an epic would be now a .7 chance so it would be 30%. This is the best solution. Although, thanks for the help!