How can I duplicate terrain with a script?

How can I duplicate smooth terrain?

I already had an attempt in doing this but I failed.
This is the script I tried:

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!