Table insert bug or some problem

i got a problem on making table thing

In short, this style of script makes this result.

local Table = {{{1,1},{1,2}},{{2,1},{2,2}}}

table.insert(Table[2], {3,3})

print(Table)
                {
                    [1] =  ▼  {
                       [1] =  ▼  {
                          [1] = 1,
                          [2] = 1
                       },
                       [2] =  ▼  {
                          [1] = 1,
                          [2] = 2
                       }
                       [3] =  ▼  {
                          [1] = 3,
                          [2] = 3
                       }
                    },
                    [2] =  ▼  {
                       [1] =  ▼  {
                          [1] = 1,
                          [2] = 1
                       },
                       [2] =  ▼  {
                          [1] = 1,
                          [2] = 2
                       },
                       [3] =  ▼  {
                          [1] = 3,
                          [2] = 3
                       }
                    }
                 }

well, yes. the script not print this. so i said “this style of script”
here is the script causing bug

for i = 1, XDirection, 1 do
	print("right1",Num, PathFinding[Num], PathFinding[1])
	table.insert(PathFinding[Num], {LastPath[1], LastPath[2]+i})
	print("right2",Num, PathFinding[Num], PathFinding[1])
end

same style of script. right?
so it prints

00:22:27.361  right1 2  ▼  {
                    [1] =  ▼  {
                       [1] = 3,
                       [2] = 6
                    }
                 }  ▼  {
                    [1] =  ▼  {
                       [1] = 3,
                       [2] = 6
                    }
                 }  -  Client - GameWork:468
  00:22:27.361  right2 2  ▼  {
                    [1] =  ▼  {
                       [1] = 3,
                       [2] = 6
                    },
                    [2] =  ▼  {
                       [1] = 3,
                       [2] = 7
                    }
                 }  ▼  {
                    [1] =  ▼  {
                       [1] = 3,
                       [2] = 6
                    },
                    [2] =  ▼  {
                       [1] = 3,
                       [2] = 7
                    }
               }  -  Client - GameWork:470

so, problem is Item that must only be put in one table got put in two tables.

this problem happens even i use PathFinding[Num][#PathFinding[Num]+1] = {LastPath[1], LastPath[2]+i}

I just tested your script and it ran as intended for me. Are you sure there are no lines of code copying the table with index 2 to the table with index 1? Try looking for possible RunService connections or loops running at other functions.

Here’s the output showed for me:

right2 2  ▼  {
                    [1] =  ▼  {
                       [1] = 3,
                       [2] = 6
                    },
                    [2] =  ▼  {
                       [1] = 3,
                       [2] = 7
                    }
                 }  ▼  {
                    [1] =  ▼  {
                       [1] = 3,
                       [2] = 6
                    }
                 }

And here is the code used to simulate your tables:

local XDirection = 1

local Num = 2

local PathFinding = {
	[1] = {{3,6}},
	[2] = {{3,6}}
}

local LastPath = {3,6}


for i = 1, XDirection, 1 do
	print("right1",Num, PathFinding[Num], PathFinding[1])
	table.insert(PathFinding[Num], {LastPath[1], LastPath[2]+i})
	print("right2",Num, PathFinding[Num], PathFinding[1])
end

Oh, maybe that’s the problem. Two tables contains same table from same variable as you said.
should i use Table[2] = table.clone(**VariableName**)?

edit : ok! table.clone working well. thanks!