So I have a problem with my module script where is says there is a nil value I have tried going on the dev forum and looking it up, and just simply looking up the error but here is the script
P.S this is for a egg system
local petModule = {} petModule.pets = { ["Epic"] = {game.ReplicatedStorage.pets.LavaBird}; ["Rare"] = {game.ReplicatedStorage.pets.StereoPet}; ["Uncommon"] = {game.ReplicatedStorage.pets.DodgeBall}; ["Basic"] = {game.ReplicatedStorage.pets.BasicDoggo}; } petModule.rarityTable = { ["Epic"] = 4; ["Rare"] = 16; ["Uncommon"] = 30; ["Common"] = 50; } petModule.chooseRandomPet = function() local randomNumber = math.random(1,100) local counter = 0 for rarity, weight in pairs(petModule.rarityTable) do counter = counter + weight if randomNumber <= counter then local rarityTable = petModule.pets[rarity] local chosenPet = rarityTable[math.random(1, #rarityTable)] return chosenPet end end end return petModule
local rarityTable = petModule.pets[rarity] local chosenPet = rarityTable[math.random(1, #rarityTable)]
I think the problem is that there is nothing called "Rarity" In Petmodule.pets, I might be wrong.
You have a naming mismatch. Your code will error on cases where the chosen Rarity is "Common", when in reality you're looking for "Basic." Try changing line 16's ["Common"] to line 07's "Basic", or vice versa.