Invalid argument #1 to Pairs (table expected, got Color3)

Code:

local SearchKeyword = string.lower(tostring(Input))
		CurrentTable = {}
		
		for categoryindex,category in pairs(Catalog) do
			if category ~= "Skintones" then
				for subcategoryindex,subcategory in pairs(category) do
					for index,value in pairs(subcategory) do
						local stringword = subcategory[index].Name
						if string.find(stringword,SearchKeyword) then
							print("Found")
							table.insert(CurrentTable,value)
						end
					end
				end
			end
		end

Really unsure what could be triggering it, the code looks just fine. It’s basically a search system to find similar items with same name elements, but I basically made it so it avoids the category “Skintones” in the beginning. Color3 isn’t being used at all.

What’s happening here is in one of your for loops the argument being passed as a table is actually a Color3, which line is the error on?

This line:

for index,value in pairs(subcategory) do

And, as an example, here’s how one of the subcategories’ values looks like.

[2] =  {
		["Creator"] = "OceanOrbs",
		["ID"] = 6105519422,
		["Name"] = "BubbleGum Candy (1.0)",
		["Price"] = 15,
		["Type"] = 42
	},

Could you print out the subcategories?

1 Like

Yeah; printing out subcategories works out totally fine. When I just introduce that error line I posted above, it keeps bringing up the error. I can mask it any way I want, it’ll still reproduce it.

Try printing subcategory before looping through it. This should end up showing you the sub-category that causes the error.

Edit: I meant to put subcategory, not category

Actually, I just printed out the category and it seems that it did pull a whole Color3 table from Skintones. How’s that possible if I filtered it out tho?

Edit: Subcategory pulls normal items.

Could you paste this output? (character min)

1 Like

Prior to doing so, can you just post where to put prints at before printing the output? Just so I don’t need to bother you with so many messages.

Actually, the error might be right here. Instead of category, it needs to be categoryindex, since category is not a string, therefore this line probably doesn’t function correctly.

Omg, you’re totally right… Let me try that real quick.

Another error emerges! LOL

Error line:

local stringword = subcategory[index].Name

It’s the same issue, although this time subcategory[index] is pointing to a number instead of an object

Just removed the index portion from the subcategory and it still seems to do it. Let me try doing a print real quick.

Actually I see the issue here, .Name is a property for parts and whatnot, so the script is reading .Name as a property and not a table index. try doing subcategory[index]["Name"]

Actually, you can reference things in dictionaries with a dot.

eg:
local test = {a = 1}
print(test.a) — prints 1

Yeah, the dot can also be used, just like dolphin said. But, regardless, it still doesn’t resolve the issue.

I put in so many prints, no number is being used at all, yet it does register things that are matching up with the search text. The error keeps popping up tho.

Your right, what I mentioned is an issue that used to be prevalent years ago but I guess its been fixed, albeit I will still always use name with a lowercase N

Maybe before this, add
if not subcategory[index] then continue end

1 Like

I’ve been reading this topic a little while watching you all discuss it and I’m confused as to why no one asked to see the Catalog variable, it seems to be very important in resolving this issue.

2 Likes