Taking a value out of a table ina module

this a server script

	local module1 = require(script.Parent.PetModule)
	local pet = module1.chooseRandomPet()
	print(pet.Name.." Selected")

and this is the module

local petModule = {}

petModule.pets = {
	["Secret"] = {
		game.ReplicatedStorage["Pet Storage"].Ctulu;
	["Legendary"] = {
		game.ReplicatedStorage["Pet Storage"]["Shadow Dominus"];
	["Epic"] = {
		game.ReplicatedStorage["Pet Storage"].Ultimus;
	["Rare"] = {
		game.ReplicatedStorage["Pet Storage"].Reaper;
	["Uncommon"] = {
		game.ReplicatedStorage["Pet Storage"]["Demon bee"];
	["Common"] = {
		game.ReplicatedStorage["Pet Storage"].Pumpkin;

--weighted selection
-- 100 total wight 
petModule.rarities = {
	["Secret"] = 0.1;
	["Legendary"] = 2.9;
	["Epic"] = 8;
	["Rare"] = 18;
	["Uncommon"] = 30;
	["Common"] = 41;

petModule.chooseRandomPet = function ()
	local randomNumber = math.random(10/100,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)]
			return chosenPet
return petModule

is there a way to take out the selected pet ( server script) rarity from the module?

You would need to handle that from within the module script itself.

local chosenPet = rarityTable[math.random(1,#rarityTable)]
rarityTable[chosenPet] = nil
return chosenPet

Like this?

nope but do you know a way to return more than 1 value from the module? that would fix.

because i tried adding another thing to return chosenPet

return chosenPet , r – this is the rarity

the problem is that in the server script i gets onlu the chosenPet and not r

local chosenPet = rarityTable[math.random(1,#rarityTable)]
rarityTable[chosenPet] = nil
return chosenPet

This would work but I’m assuming it’s not the behavior you’re trying to achieve.

If you need to return multiple random pets just run a loop inside the module function itself, collect the selected pets in a table value and return that table value.

it is not but i adden another table in the module script that have pet name paired with thair rarities
so ican just check the rarity by getting the table and using the chosenPet name.

but i don’t know how to return both the rarity and the pet.Name from the module

nvm i was able to fix it but thank you for helping me