When you are iterating through the table Part1, the owned variable will return a string, which then you are trying to iterate over, which is not possible as you can only iterate over a table.
Not much I can really do to help then at the moment, until I can see a snippet of the code which defines the ownedPlots table, so once you’ve posted it I’ll be back
Your issue seems to be that ownedPlots is an array full of strings. Whenever it prints “owned Part1”, you don’t actually check the type of it. Part1 is actually a string. You can tell Part1 isn’t an array, because if it was, it’d print “table: some_random_letters_here”
If you want to turn that string into the Part1 variable, you’ll have to use an if statement.
EG:
if (owned == "Part1") then
owned = Part1; -- Part1 = array reference;
elseif (owned == "Part2") then -- etc
I’m assuming you want to iterate a table called Part1 when your first loop encounters a value "Part1" in ownedPlots. What you should do is create a table of tables (a dictionary) where you put tables like Part1, Part2, etc. to be able to index them easily:
local list = {
Part1 = {6,8,2,4},
Part2 = {1,2,3,4}
}
for i, owned in pairs(ownedPlots) do
local vals = list[owned]
if vals then
for i, adjacentToOwned in pairs(vals) do
print(adjacentToOwned, "is adjacent to", owned)
end
end
end