You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
A Module script for different rarities in a hatching system -
What is the issue? Include screenshots / videos if possible!
it says attempt to get the length of nil value -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
i tried changing the brakets and checking it over but nothing its happening
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local Avgmodule = {}
local AvgList = game.ReplicatedStorage.AvgPets
-- Put each pet to rarity
Avgmodule.items = {
["Special"] = {
AvgList["Big Boi"]
};
["Legendary"] = {
AvgList["sus sus"]
};
["Rare"] = {
AvgList["kinda sus] , AvgList["Little bit of salami"]
};
["Common"] = {
AvgList["small morsel of salami"] , AvgList["sqauare"]
};
}
-- set rarity weights
Avgmodule.rarities = {
["Special"] = 1;
["Legendary"] = 5;
["Rare"] = 30;
["Common00"] = 64;
}
--Function of choosing pet
Avgmodule.RandomPet = function()
local Ranum = math.random(1, 100)
local counter = 0
for rarity, weight in pairs(Avgmodule.rarities) do
counter = counter + weight
if Ranum <= counter then
local raritytable = Avgmodule.items[rarity]
local choosenitem = raritytable[math.random(1, #raritytable)] --where the error is coming from
return choosenitem
end
end
end
return Avgmodule
*some context: Avg is an abbv for Average like this is an Average egg but some stuff may still be named with “pet” because I was remaking a script from AlvinBlox
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.