I’m following an Alvinblox tutorial since I’m a beginner at coding, but I do know quite a lot about coding fundamentals so I’ll try to explain this as well as I can.
I have a module script called “petModule” and I cant figure out how to get the items inside of subtables(is that what they’re called?) and I need to in order to return the rarity of the pet, but I just don’t know how.
The pet returning does it somehow(actually it only does it on the simple rarity, everything else returns nil) but I need a new function to return a different part of the table, the pet rarity.
Don’t know if that makes sense but I’ll just put the module here
local petModule = {}
local petFolder = game.ReplicatedStorage.Pets
petModule.pets = {
[(rarity)] = {
petFolder[(pet)]; -- (pet) is just what I'm putting here, not the actual code --
} ;
[(rarity)] = {
petFolder[(pet);
} ;
[(rarity)] = {
petFolder[(pet)];
} ;
[(rarity)] = {
petFolder[(pet)];
petFolder[(pet)];
petFolder[(pet)];
} ;
[(rarity)] = {
petFolder[(pet)];
petFolder[(pet)];
} ;
}
petModule.rarities = {
[(rarity)" = 5; -- ditto --
[(rarity)] = 5;
[(rarity)] = 10;
[(rarity)] = 25;
[(rarity)] = 55;
}
petModule.ChooseRandomPet = function()
local randomNumber = math.random(1,100)
for rarity, weight in pairs(petModule.rarities) do
local count = 0
count = count + weight
if randomNumber <= count then
local rarityTable = petModule.pets[rarity]
local chosenPet = rarityTable[math.random(1,#rarityTable)]
return chosenPet
end
end
end
petModule.GetRarity = function()
local rarity = petModule.pets.
return rarity
--what I tried, but then I found out why this wouldnt work--
end
return petModule
thanks! I might not be able to reply for a while.
edit: the other half of the text is red, weird