2 tables that are same, arent the same

hello developers,

so i have 2 tables;

Table1 = {Enum.KeyCode.A,Enum.KeyCode.B,Enum.KeyCode.C,Enum.KeyCode.D}
table2 = {}

i add into table 2, what buttons you press, so when you do type in ABCD, when you compare it.

So i print every part of both tables;
image

1 print every part of the table using table1[number], and so with table 2, i also print the entire table. than i compare the 2 together, and it gets false, but its litterly the same??!?!??!

Most likely it’s because that, albeit they have the same content, they point to 2 different memory addresses and when you do an equality check, it compares the memory addresses and thus why it errors (Correct me if I’m wrong, not sure how using == on a table works)

You’re probably better off looping through Table1 and see if the same index in Table2 is the same item

Simple example

table1 = {Enum.KeyCode.A,Enum.KeyCode.B,Enum.KeyCode.C,Enum.KeyCode.D}
table2 = {Enum.KeyCode.A,Enum.KeyCode.B,Enum.KeyCode.C,Enum.KeyCode.D}

local passesTest = true

for i, key in ipairs(table1) do
	if table2[i] == key then
		continue
	end
	
	passesTest = false
	break
end

if passesTest then
	-- Do something
end
1 Like