So I have this Rarity Module, I want to multiply all the rarities by a attribute the player has called Luck Multiplier (for anyone curious the multiplier is 1.1) but I’m getting this error
The error is on line 39 where its multiplying
local ServerStorage = game:GetService("ServerStorage")
local Drops = ServerStorage:WaitForChild("Drops")
local Rarity = {}
Rarity.Parts = {
["Ultra Mythic"] = Drops.UltraMythicPart;
["Mythic"] = Drops.MythicPart;
["Legendary"] = Drops.LegendaryPart;
["Epic"] = Drops.EpicPart;
["Super Rare"] = Drops.SuperRarePart;
["Rare"] = Drops.RarePart;
["Common"] = Drops.CommonPart;
}
Rarity.Rarities = {
["Ultra Mythic"] = .05;
["Mythic"] = .5;
["Legendary"] = 1.4;
["Epic"] = 8;
["Super Rare"] = 14;
["Rare"] = 20.05;
["Common"] = 58;
}
function Rarity.GetPart(player)
local randomNum = math.random(1,100)
local counter = 0
for _, rare in pairs(Rarity.Rarities) do
if Rarity.Rarities[rare] ~= "Common" then
Rarity.Rarities[rare] *= player:GetAttribute("LuckMultiplier")
end
end
for rarity, weight in Rarity.Rarities do
counter += weight
if randomNum <= counter then
return Rarity.Parts[rarity]
end
end
end
return Rarity
First of all, you are comparing the value here not the index. if Rarity.Rarities[rare] ~= "Common" then. Also, try printing player:GetAttribute("LuckMultiplier") as it seems like it is nil.
In the for loop you did _, rare. The _ represents the index and the ‘rare’ represents the value, so Rarity.Rarities[rare] does not exist because you are searching the table for a number value. Instead, change the _, rare to Rareness, Percentage, with the Rareness value representing the name (common, uncommon, etc) and the percentage representing, well, the percentage.