Help with modules

I have this module and its supposed to be pets sorted by rarities.

    local module = {}
    	module.pets = {
    		["Common"] = {
    			{"Bunny"},
    			{"Mouse"},
    		},
    		["Uncommon"] = {
    			{"Horse"},
    			{"Elephant"},
    		},
    		["Rare"] = {
    			{"Bee"},
    			{"Wasp"},
    		},
    		["Epic"] = {
    			{"Moose"},
    			{"Cow"},
    		},
    		["Legendary"] = {
    			{"Dragon"},
    			{"Hydra"},
    		},
    		["Mythic"] = {
    			{"Dark Dragon"},
    			{"Guardian"},
    		},
    	}
    return module

I have another script like this:

    local module = require(game.ReplicatedStorage.petModule)
    print(module.pets["Common"][1])

I am trying to make the script look under the “Common” category, and choose the first item(Bunny). How would i do that?

3 Likes

with your modulescript, it should be:

module.pets["Common"][1][1]

1 Like

Your attempt is very close, just one level up. The name of the first pet in the Common category would be module.pets.Common[1][1], since Command[1] is a table which itself has another element which is the name of the pet.

You could make this much more intuitive by adding a name field in pets:

module.pets = {
    ["Common"] = {
    	{Name = "Bunny"},
    	{Name = "Mouse"},
    },
    -- ...

To make this script work remove the {} around the pet names!

    	module.pets = {
    		["Common"] = {
    			"Bunny",
    			"Mouse",
    		},
    		["Uncommon"] = {
    			"Horse",
    			"Elephant",
    		},
    		["Rare"] = {
    			"Bee",
    			"Wasp",
    		},
    		["Epic"] = {
    			"Moose",
    			"Cow",
    		},
    		["Legendary"] = {
    			"Dragon",
    			"Hydra",
    		},
    		["Mythic"] = {
    			"Dark Dragon",
    		    "Guardian",
    		},
    	}
    return module```