Table.find() always return nil

So, I’m making a Chess board system where you can put a FEN in and return white’s move and black’s move, the problem I’m having here is that when I try to sort these pieces into their tables the table.find() always return nil regardless what I do

local BlackPieces = {"p", "r", "n", "b", "q", "k"}
local WhitePieces = {"P", "R", "N", "B", "Q", "K"}

local function SortPieces(PieceCoordinates)
	local WhitePieces = {}
	local BlackPieces = {}
	for _, PieceData in pairs(PieceCoordinates) do
		if table.find(WhitePieces, PieceData[1]) then
			table.insert(WhitePieces, PieceData[1])
		elseif table.find(BlackPieces, PieceData[1]) then
			table.insert(BlackPieces, PieceData[1])
		end
		print(PieceData[1], table.find(WhitePieces, PieceData[1]))
		print(PieceData[1], table.find(BlackPieces, PieceData[1]))
	end
	return {WhitePieces, BlackPieces, PieceCoordinates}
end

and the PieceCoordinates is just an array that looks smt like this

{
{"r" ,{1,1}, {"n" ,{1,2}, {"b" ,{1,3},...
}

and this is what it print out

I made sure its not a dictionary but idk if the tables in the picture is a dictionary when I use table.insert()
and when I print out table.find(WhitePieces, "P") it returns nil instead of 1
I checked about this topic and theres seem to be nothing about it

You’re creating new empty tables called WhitePieces and BlackPieces inside the function, which shadows the original tables at the top that have the piece types in them.

So table.find() is searching the empty tables instead of the ones with “P”, “R”, “N”, etc.

Rename the local tables to something else like SortedWhite and SortedBlack.

My bad I forgot, thanks for telling me..