im making an egg hatching system and i sent arguments to a for loop on the modulescript and it prints out the error "attempt to index nil with ‘Common’ "
there is probably a solution to this but im too stupid to figure it out
heres a part of the modulescript
petModule.chooseRandomPet = function(test)
local randomNum = math.random(0.0001,100)
local counter = 0
for rarity, weight in pairs(petModule.rarities) do
counter += weight
if randomNum <= counter then
local rarityTable = petModule.pets.test[rarity]
local chosenPet = rarityTable[math.random(1,#rarityTable)]
return chosenPet
end
end
end
and here is the script that sends the argument
player:WaitForChild("Data"):WaitForChild("Coins").Value -= cost
local pet = petModule.chooseRandomPet("CommonEgg")
game.ReplicatedStorage:WaitForChild("HatchEgg"):FireClient(player,pet)
The reason why it’s an error of existence is whether intentional or not they were looking up the wrong thing since the following 2 lines are identical.
petModule.pets.test
petModule.pets[“test”]
They likely meant to use the string in test as reference
petModule.pets[test]
It could be considered a syntax error since they unintentionally used the wrong syntax. But it is worth noting that the error generated is related to existence not syntax specifically.