How can i add a variable to a module?

So, yeah, it is basically what the title says.
I want to create some kind of inventory using IDs, but to do that, i have to create the variables to store them. As i don’t have a set number of slots, i was thinking on creating each module variable outside the module itself, but i have no idea how to do it.

I think it would better to use a table instead. Pass in the slot number as the index and the id as the value. This way you don’t have to create a variable for each different ID.

local module = {
	itemTable = {}
}

But if you want to add a variable, you would just add it to the top of your script. As you can see this becomes redundant, which is where table comes in :slight_smile:

local var = ...
local module = {}
1 Like

Do you know how i can iterate over it? I for looped it, but nothing appeared, no error, nothing.
The module:

local idData = {
	idBank = {
		a0001 = {
			name = "yes"
		}
	}
}

return idData

The Local Script:

local ID = require(game:GetService("ReplicatedStorage").ID)
local idBank = ID.idBank
for i, v in ipairs(idBank) do
	print(i, " ", v)
end

Use pairs not ipairs.
ipairs only works if the index is an integer. Your indexes are strings.

2 Likes