How do I retrieve the indexed value from my table?

This is my table:

	invmod:AddItem(plr,{
		Name = "Wand",
		Type  = "Magic Weapon",
		State = "Unequipped",
		UniqueID = nil
	})

And this is how i’m trying to retrieve it:

		for i,x in pairs(item) do
			print(i,x)

		end

Now, this prints all I intend it to (I generate a random ID once I create the item in another script)

  State Unequipped
  Type Magic Weapon
  Name Wand
  UniqueID EFC0779A-FD77-4949-A657-A320E6967691

But I don’t know how to only get the last value which is UniqueID.
--print(x) this prints nil
print(i,x) this prints nil too

How do I go about this?

Can’t you just do item.UniqueID ?

nil (x4)
print(i.UniqueID) with this line.

I’m assuming the for loop code is for :AddItem? Is the key the table? I said item, not i.

You are creating dictionary so @incapaxx’s solution should be working.

You are looping through the item, i is the current key, and x is the current value you don’t have to loop through it and all you have to do is item.UniqueID.

i is the current key, and x is the current value is what you should say

oh my bad (: :heart: :heart: :heart:

1 Like

This is a script for my gui, I may not have proposed this correctly:
I have a buttons table and I add a new button in it and the item info (which is v)

						local itemFrame = script.ItemPreview:Clone()
						itemFrame.ItemName.Text = v.Name
						itemFrame.Parent = x
						local buttonTable = {
							[1] = itemFrame,
							[2] = v,
						}
						table.insert(buttons,buttonTable)

And then I loop through the buttons table:

	for _,v in pairs(buttons) do
		for i,x in pairs(v[2]) do
			--print(x)
			print(i.UniqueID)
		end
for _,v in pairs(buttons) do
	print(v[2].UniqueID)
end
1 Like

Perhaps v[2], since that seems to be where then unique id is

2 Likes

Didn’t read through the first script

ì is the uniqueID, doing i.UniqueID doesn’t make sense, it’s as if the key was a table and it had a value inside of it.

1 Like

Alright, alright! You guys are correct I was trying to print the UniqueID of the current key, and not from the table. Thanks for the understanding!

1 Like

I did, good sir! :slight_smile: