How do I locate in a table?

Error code: attempt to index number with 'rarity'

for i,v in ipairs(items) do
	local newItem = inventoryGui.Item:Clone()
	newItem.Name = i 
	newItem.Parent = inventoryGui
	newItem.Image = "1494567839"
	newItem:WaitForChild("ItemName").Text = i
	if i.rarity == 1 then -- i.rarity doesnt work
		newItem.Item.Backgroundcolor3 = Color3.new(255, 255, 255)
    elseif i.rarity == 2 then -- same thing here
        newItem.Item.Backgroundcolor3 = Color3.new(0, 0, 0)
    end
end

This is the table:

local profile = {
	Inventory = {
		items = {
           "item" = {
              rarity = 1, -- How do I locate this?
              statusValue = false,
           },
        },
	},
}

I is basically how many times it has looped through the table. Use V instead.

1 Like