How to print these table items

Hello!

I’m trying to get names of the items in the Drop table.

local objectData = {
	["Tree"] = {
		Name = "Tree",
		
		Tier = 1,
		MaxHealth = 10,
		
		Drop = {
			-- Trying to get the Stick, Leaves and Log
			["Stick"] = 2,
			["Leaves"] = 2,
			["Log"] = 3,
		},
	}
}

return objectData

I’ve been trying to get what I want for about a day now and I have kind-of achieved it with this code:

for i, item in pairs(drop) do
	print(item)
end

However, this prints the value of the item and not the name. But I’m pretty sure I’m on the right track!

Excuse me for the lack of knowledge in ModuleScripts, I am just now starting to get used to them.

Try

for i, item in pairs(drop) do
	print(i,item)
end

The index is the value name, the second argument(item) is the value.

Literal godsend, thanks for the explanation as well!

To clear your confusion on “index”, it’s basically the i .