Hey everyone! I’m currently working on a simulator-style game where player do something to find random loot. Each item has a rarity, and I want the player’s “Luck Multiplier” to increase the chances of getting Rare and Legendary items, like how it works in many other games.
Right now, I’m testing with a Luck Multiplier of 10, but I still keep getting mostly Common items. I expected to be getting at least some Rare or Legendary items, but that’s not happening.
Here’s how my system is currently set up:
PlayerDataManager (simplified)
data = {
diggingLuckMultiplier = 10
}
ItemsData Module (simplified)
ItemsData.RarityWeights = {
Common = 69,
Uncommon = 20,
Rare = 10,
Legendary = 1,
}
ItemsData.ItemsByRarity = {
Common = {
{ Name = "Banana", Value = 1, Tool = itemTools:WaitForChild("Banana")},
},
Uncommon = {
{ Name = "Car Battery", Value = 5 },
},
Rare = {
{ Name = "Vintage Toy", Value = 25 },
{ Name = "Collector Card", Value = 30 },
},
Legendary = {
{ Name = "Diamond Ring", Value = 150 },
{ Name = "Ancient Coin", Value = 200 },
}
}
LootService (Rarity Roll Logic)
function LootService.RollRarity(playerLuckMultiplier: number)
local totalWeight = 0
local adjustedWeights = {}
for rarity, baseWeight in pairs(ItemsData.RarityWeights) do
local adjusted = baseWeight
if rarity ~= "Common" then
adjusted *= playerLuckMultiplier
end
adjustedWeights[rarity] = adjusted
totalWeight += adjusted
end
local roll = math.random() * totalWeight
local cumulative = 0
for rarity, weight in pairs(adjustedWeights) do
cumulative += weight
if roll <= cumulative then
return rarity
end
end
return "Common" -- fallback
end