Issues with Terrain:WriteVoxelChannels()

Hello! I am trying to create a script that generates a “chunk” of terrain data and then loading it using Terrain:WriteVoxelChannels()

Now, the issue is that, when I’m trying to “fill one block”, an entire slice becomes filled. I have no idea why this happens.

I have searched for this issue on devforums and even checked out the docs for guidance, but I still haven’t been able to fix this issue.

Here’s my code:

Script 1

	return function(Size)

	local materials = table.create(Size, table.create(Size, table.create(Size, Enum.Material.Grass)))
	local solidOcc = table.create(Size, table.create(Size, table.create(Size, 0)))
	local waterOcc = table.create(Size, table.create(Size, table.create(Size, 0)))
	
	solidOcc[1][3][4] = 1
	
	--End
	return {SolidMaterial=materials, SolidOccupancy = solidOcc, LiquidOccupancy = waterOcc}
	
end

Script 2

local voxelchann = chunkGenerator(10)
local reg = Region3.new(Vector3.zero, Vector3.one * 40)
workspace.Terrain:WriteVoxelChannels(reg, 4, voxelchann)

chunkGenerator is the function from above

If someone could help me on this, I’d appreciate it alot!

OOPS! after looking back on it, i found the issue was my issue with not understanding what table.create really does… :sweat_smile:
if anybody else has the same issue, i replaced that table.create stack with a function that makes a table like so:

local createEmptyTable = function(base, size)
		local start = {}
		for i = 1, size do
			for j = 1, size do
				for k = 1, size do
					if not start[i] then
						start[i] = {}
					end
					if not start[i][j] then
						start[i][j] = {}
					end
					
					start[i][j][k] = base
				end
			end
		end
		return start
	end