Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to I call a table within a table, and their variables?

So I'm working on a inventory system and I dont know how I can call the tables inside a table and the variables.

Heres the tables in the modulescript I'm trying to call.

local items = {
		
	----||Item 1|||----
	{name = "Item1",
	itemid = "000000f",
	itemweight = 0,	
	},
	----||Item 2|||----
	{name = "Item2",
	itemid = "0000007",
	itemweight = 0,	
	},
	----||Item 3|||----
	{name = "Item3",
	itemid = "00200FF",
	itemweight = 0,	
	},
	

}

return items

I only really know how to call Items but not the tables in it, or their variables. How can I do this?

1 comment

0

Example: print( requiredModule[2].name ) -- Item2

1 answer

✓ Accepted answer

Like this:

local module = require() --your module
local itemInt = 1 --this depends on which item you want to use.

print(module[itemInt]) -- will print out a table,
print(module[itemInt].name) --will print out the name
print(module[itemInt].itemid) --will print out the id
print(module[itemInt].itemweight) --will print out the itemweight.

2 comments

0

I will try this right away.

1

This was exactly what I needed! Thank you!

This discussion is preserved as it was. New answers, comments, and votes are closed.