Problem With Module Scripts

Hey. I have a really small problem that is affecting me a lot. Right now, I have this code in a module

local pets = {
	["Dog"] = Vector2.new(1,270),
	["Cat"] = Vector2.new(271,540),
	["Turtle"] = Vector2.new(541,740),
	["Bunny"] = Vector2.new(741,900),
	["Ferret"] = Vector2.new(901,1000),
}

return pets

Whenever I require it it gives me this order (Or something like it I dont remember perfectly) - Turtle, Cat, Dog, Ferret, Bunny. The problem is, I want it to give it to me in written order.

1 Like

Correction. It actually prints out like this image

You’d have to change the indexes to numbers or some sort of ordered character because dictionaries are not ordered naturally I don’t think
(may not be true though)

You may be right because I noticed it’s in alphabetical order

Dictionaries aren’t ordered, you will need to index by number or convert it to an array and then sort it. Why do you need it to be in a specific order? There may be another way to solve this problem if the context was made clear.

Maybe OP can do something like

local animals = {
[1] = {"Cat"},
[2] = {"Dog"}
}

if you need multiple animals in one index

I am calling it from a Gui then turning it into a list from most common to rare. It would look ugly if it was out of order. I need to use the name from the dictionary to get the model from replicated storage so I can use it in a viewport.

I think the solution would be to format it as [“1 Dog”] , [“2 Cat”] and use string manipulation.

The Vector2 is very important so this won’t work. I think I may have found a solution

Why can’t you keep the order of the GUI separate from this list? Simply keep the order of the rarity and refer to that.

1 Like

This has the added benefit of allowing you to keep this information separate from the rarity(so that you can change that at will) without having to muck up this table

1 Like

Sorry I made a mistake, correction:

local animals = {
    [1] = {
                ["Dog"] = Vector2.new()
            },
}
1 Like