- What do you want to achieve? I want to fix it
-
What is the issue?
- What solutions have you tried so far? I tried to edit the script.
The Part Of The Script: ( Is not the full one)
local rarityTable = petModule.pets[rarity]
local chosenPet = rarityTable[math.random(1,#rarityTable)]
The Module Script:
local petModule = {}
petModule.pets = {
["Mythic"] = {
};
["Legendary"] = {
};
["Epic"] = {
};
["UnCommon"] = {
game.ReplicatedStorage.Pets.BlackCaterpillar;
game.ReplicatedStorage.Pets.WhiteCaterpillar;
};
["Common"] = {
game.ReplicatedStorage.Pets.GreenCaterpillar;
game.ReplicatedStorage.Pets.DarkGreenCaterpillar;
game.ReplicatedStorage.Pets.LightGreenCaterpillar;
};
}
petModule.rarities = {
["Mythic"] = 1;
["Legendary"] = 3;
["Epic"] = 17;
["UnCommon"] = 24;
["Common"] = 55;
}
petModule.chooseRandomPet = function()
local randomNumber = math.random(1,100)
local counter = 0
for rarity, weight in pairs(petModule.rarities) do
counter = counter + weight
if randomNumber <= counter then
local rarityTable = petModule.pets[rarity]
local chosenPet = rarityTable[math.random(1,#rarityTable)[#rarityTable]]
return chosenPet
end
end
end
return petModule