My script to add to a table wont work

local wallsfound = {"test"}
local JJ = game.Workspace.JJ
local FOV = JJ.FOV

for i,v in pairs(game.Workspace.Walls:GetChildren()) do
	v.Name = "Wall_"..i
end

FOV.Touched:Connect(function(what)
	if what:FindFirstChild("Wall") then
		if not wallsfound[what.Name] then
			table.insert(wallsfound, what.Name)
		end
	end
end)

game.Close:Connect(function()
	print(wallsfound)
end)


while true do
	local range = math.random(1, 100)
	JJ.Humanoid.WalkToPoint = Vector3.new(range, 3, range)
	wait(3)
end

The table looks like this:

{
                    [1] = "test",
                    [2] = "Wall_3",
                    [3] = "Wall_8",
                    [4] = "Wall_5",
                    [5] = "Wall_8",
                    [6] = "Wall_3",
                    [7] = "Wall_8",
                    [8] = "Wall_5",
                    [9] = "Wall_3",
                    [10] = "Wall_3",
                    [11] = "Wall_3",
                    [12] = "Wall_3",
                    [13] = "Wall_3",
                    [14] = "Wall_5",
                    [15] = "Wall_8",
                    [16] = "Wall_2",
                    [17] = "Wall_2",
                    [18] = "Wall_3",
                    [19] = "Wall_5"
                 }

what exactly are you trying to accomplish?

Im trying to make an AI thing but first I need to know what walls it has already hit to see if it can hit them all.

table.insert will always insert values with an array like format. However, you’re checking to see if values exist in the table as if it was a dictionary.

Change this event connection

FOV.Touched:Connect(function(what)
	if what:FindFirstChild("Wall") then
		if not wallsfound[what.Name] then
			table.insert(wallsfound, what.Name)
		end
	end
end)

to this

FOV.Touched:Connect(function(what)
	if what:FindFirstChild("Wall") then
		if not table.find (wallsfound, what.Name) then
			table.insert(wallsfound, what.Name)
		end
	end
end)

or to this

FOV.Touched:Connect(function(what)
	if what:FindFirstChild("Wall") then
		if not wallsfound[what.Name] then
		     wallsfound[what.Name] = what
		end
	end
end)