Table dissapearing for no reason

So im programming some perlin noise and at the moment im trying to break/place voxels but its erroring say said voxel does not exist.

if mapGet(chunks, offset.X/16, offset.Y/16, offset.Z/16) then
		
		local localdata = {}
		
		for x=1, 16 do
			data[x + offset.X] = {}
			localdata[x] = {}
			
			
			for y=1, 16 do
				data[x + offset.X][y + offset.Y] = {}
				
				print(x + offset.X, y + offset.Y, data[x + offset.X][y + offset.Y])
				
				localdata[x][y] = {}
				
				for z=1, 16 do
					local h = heightMap(x + offset.X, z + offset.Z)
					
					data[x + offset.X][y + offset.Y][z + offset.Z] = y + offset.Y < h and "block" or "air"
					localdata[x][y][z] = y + offset.Y < h and "block" or "air"
				end
			end
		end

		chunks[offset.X/16][offset.Y/16][offset.Z/16] = renderer:Render(16,localdata, offset)
	end

This is my code and through printing I can very well see that blocks are being saved into data. But then when I do this data[pos.X][pos.Y] im getting nil. Any help is apreciated.

1 Like

Does the debug print in the 2nd for loop print the pos.Y value as nil or does it say it’s there? Also, which part exactly is erroring? The same script or a different one?

The same script is erroring, the placement section only though. And no prints are nil.

Can you show the placement section code?

I would prefer actually not too, but I know that it is not erroring. I was printing the key I was using and I found the object in the table.

Well, my idea was that you’re indexing the table in a wrong way in the placement section code. Try placing a breakpoint in it at the spot where you index the table, preferably in this way since data[pos.X] isn’t nil:

local posX = data[pos.X]
local posY = posX[pos.Y] --breakpoint here

then explore the contents of posX once the breakpoint is hit, in order to make sure it’s the valid table and a valid key.

I don’t think I can help you any further if you refuse to post that part’s code, but it’s fine, I hope you manage to solve your issue!

Yeah sorry but I already tried this. I can pm you the placement code I guess