Doesn't place enough blocks but it prints the location of where they're meant to be


It only places 8…


local r = {}
local c = game:GetService("ServerScriptService").LegacyTerrainManager
local terrainParts = game:GetService("Workspace").Terrain.TerrainParts
local enumtoblock = { --https://robloxapi.github.io/ref/enum/CellBlock.html
	"PlaceTerrainBlock",
	"PlaceTerrainVRamp",
	"PlaceTerrainCRamp",
	"PlaceTerrainIRamp",
	"PlaceTerrainHRamp"
}

local enumtomat = { -- https://robloxapi.github.io/ref/enum/CellMaterial.html
	"Empty",
	"MegaGrass",
	"MegaSand",
	"MegaBrick",
	"Granite",
	"Asphalt",
	"Iron",
	"Aluminum",
	"Gold",
	"Plank",
	"Log",
	"Gravel",
	"Cinder Block",
	"Stone Block",
	"Cement",
	"Red Plastic",
	"Blue Plastic"
}

local enumtoore = { --https://robloxapi.github.io/ref/enum/CellOrientation.html
	Vector3.new(0,0,0),
	Vector3.new(0,-90,0),
	Vector3.new(0,180,0),
	Vector3.new(0,90,0)
}

function GridPos(num) -- makes it so the number matches how PBSToolsTest2 LTM does it
	if num/4 - math.floor(num/4) < 0.5 then return math.floor(num/4)*4 else return math.ceil(num/4)*4 end
end

local function getpostopart(x,y,z) --converts the position passed in the function to the terrain voxel located at that position
	for i,v in pairs(terrainParts:GetChildren()) do
		for o,n in pairs(v:GetChildren()) do
			local magicstring = x..","..y..","..z
			if n.Name == magicstring then
				return n
			end
		end
	end
end
local function twoargfunc(pos,mat) 
	c.PlaceTerrainBlock:Fire(mat,pos)
end
local function sixargfunc(x,y,z,mat,block,ore) -- this code is so botched its not even funny
	local pos = Vector3.new(x,y,z)
	if mat == 0 then
		r.RemoveCell(pos)
	else
		local function blocktoblock()
			for i,v in pairs(enumtoblock) do
				if i == block+1 then
					return v
				end 
			end
		end
		local function oretoore()
			for i,v in pairs(enumtoore) do
				if i == ore+1 then
					return v
				end 
			end
		end
		if block == 0 then -- if solid then dont parse orientation
			c:FindFirstChild(blocktoblock()):Fire(tostring(enumtomat[mat+1]),pos)
		else
			c:FindFirstChild(blocktoblock()):Fire(tostring(enumtomat[mat+1]),pos,oretoore())
		end
		
	end
end -- CLEAN CODE BEGINS HERE(sike)
	
r.SetCell = --https://robloxapi.github.io/ref/class/Terrain.html#member-SetCell
	function(x,y,z,mat,block,ore) --
		if z == nil then 
		return twoargfunc(x,y) 
	else 
		return sixargfunc(x,y,z,mat,block,ore) 
	end
	end
r.SetCells = --https://robloxapi.github.io/ref/class/Terrain.html#member-SetCells
	function(region,material,block,ore)
		for x = 1, region.Max.X, 1 do
			for y = 1, region.Max.Y, 1 do
			for z = 1, region.Max.Z, 1 do
					print(x,y,z)
					r.SetCell(x,y,z,1,0,0)
				end
			end
		end
	end

r.RemoveCell = --https://robloxapi.github.io/ref/class/Terrain.html#member-SetCells
	function(pos) 
		c.DeleteBlock:Fire(getpostopart(GridPos(pos.X),GridPos(pos.Y),GridPos(pos.Z)))
		
	end
return r

Seems like the code you made works (considering it all prints), meaning that it might have to do with the Legacy Terrain Manager, since that’s what’s called to actually place the block.

Yes it does, its badly optimized but I wonder if theres a way to optimize how I place it.