Terrain won't spawn when using a script!

Hello hello hello!
I’m trying to store terrain and then spawn it at a part’s location!
The problem is that the terrain won’t appear after the region has been pasted!
The code runs until the end according to output!
Code:

function PartToRegion3(part) -- Uhh yeah I found that function somewhere
	local abs = math.abs

	local cf = part.CFrame -- this causes a LuaBridge invocation + heap allocation to create CFrame object - expensive! - but no way around it. we need the cframe
	local size = part.Size -- this causes a LuaBridge invocation + heap allocation to create Vector3 object - expensive! - but no way around it
	local sx, sy, sz = size.X, size.Y, size.Z -- this causes 3 Lua->C++ invocations

	local x, y, z, R00, R01, R02, R10, R11, R12, R20, R21, R22 = cf:components() -- this causes 1 Lua->C++ invocations and gets all components of cframe in one go, with no allocations

	-- https://zeuxcg.org/2010/10/17/aabb-from-obb-with-component-wise-abs/
	local wsx = 0.5 * (abs(R00) * sx + abs(R01) * sy + abs(R02) * sz) -- this requires 3 Lua->C++ invocations to call abs, but no hash lookups since we cached abs value above; otherwise this is just a bunch of local ops
	local wsy = 0.5 * (abs(R10) * sx + abs(R11) * sy + abs(R12) * sz) -- same
	local wsz = 0.5 * (abs(R20) * sx + abs(R21) * sy + abs(R22) * sz) -- same

	-- just a bunch of local ops
	local minx = x - wsx
	local miny = y - wsy
	local minz = z - wsz

	local maxx = x + wsx
	local maxy = y + wsy
	local maxz = z + wsz

	local minv, maxv = Vector3.new(minx, miny, minz), Vector3.new(maxx, maxy, maxz)
	--return Region3.new(minv, maxv) I COMMENTED THIS BECAUSE I DON'T THINK THAT'S THE CASE
	return minv
end
local TerrainRegion = workspace.Terrain:CopyRegion(workspace.Terrain.MaxExtents)
TerrainRegion.Parent = game.ServerStorage
wait(5)
workspace.Terrain:Clear()
wait(5)
local vReg = PartToRegion3(workspace.GenerationPart)
wait(0.1)
local Vec = Vector3int16.new(vReg.X,vReg.Y,vReg.Z)
print(1)
workspace.Terrain:PasteRegion(TerrainRegion,Vec,true) -- Code gets past this line
print(2) -- Actually reaches this print!

Anything helps!

hey there! As I am looking at your script everything looks fine, do you have any errors/warnings? can you provide more details?

Try this:

function PartToRegion3(part)
    local cf = part.CFrame
    local size = part.Size
    local halfSize = size * 0.5

    local min = cf.Position - (cf * halfSize).Position
    local max = cf.Position + (cf * halfSize).Position

    return Region3.new(min, max)
end

local TerrainRegion = workspace.Terrain:CopyRegion(workspace.Terrain.MaxExtents)
wait(5)
workspace.Terrain:Clear()
wait(5)
local region3 = PartToRegion3(workspace.GenerationPart)
local center = region3.CFrame.Position
local size = region3.Size
local pastePosition = Vector3int16.new(math.floor(center.X), math.floor(center.Y), math.floor(center.Z))
print(1)
workspace.Terrain:PasteRegion(TerrainRegion, pastePosition, true)
print(2)

Line 6: Position is not a valid member of Vector3

got this error while running the script

I tried removing .position in (cf * halfSize).Position
The code fully ran without any errors, but the same problem with the terrain not appearing happened again…

I still need help with this post :sad: