Trying to copy and paste terrain inside Region3Int16 of a part

Trying to create a function that will copy and paste terrain inside of a part. But i have no experience in using Int16 values. I’ve edited the code provided on the DevHub about copying and pasting terrain but I just cant get it to work.

The Centres of the Region3 and the TerrainRegion are different if thats a clue?

I also cannot find any other posts about this. Can someone please help?

local part = game.Workspace.Part

local min =  part.Position - (0.5 * part.Size)
local max = part.Position + (0.5 * part.Size)
local Regions = Region3int16.new(Vector3int16.new(min.X, min.Y, min.Z), Vector3int16.new(max.X, max.Y, max.Z))

local terrainRegion = workspace.Terrain:CopyRegion(Regions)
workspace.Terrain:Clear()
part:Destroy()

wait(5)

workspace.Terrain:PasteRegion(terrainRegion, Regions.Min, false)

(There is terrain inside of the block)

Not sure what’s wrong with that code in specific, but you’d make it easier on yourself just by using Terrain:FillBlock

https://developer.roblox.com/en-us/api-reference/function/Terrain/FillBlock

That’s what I was going to do, But I believe for what I’m doing there may be some complex terrain which needs removing and replacing.

Not sure if this will help you because I’m not entirely sure what you’re using this script for, but I was creating a murder mystery style game and wanted multiple terrain regions for each map (all different of course) and instead of doing complex copying and pasting of region data, I used this plugin to just load terrain region instances.

Again, not sure if it’ll actually help because I don’t know why you’re loading terrain/for what purpose, but the source code of that plugin helped me. (You can find source codes in your Roblox program files after downloading the plugin)

By the looks of the source code it can only copy and paste the whole terrain. I need to get a section of it.

it uses .MaxExtents which im pretty sure gets all the terrain

Thanks for the help anyway

2 Likes

You can try replacing * with /

Nope Didn’t work.

Its definitely to do with the Int16s. They don’t really explain them well on the DevHub.

but with a bit of testing the closer they are to 0,0,0 the closer the paste is to where I want it

Maybe try this.

local One = Vector3int16.new((part.CFrame.p + pos2).X, (part.CFrame.p - pos2).Y, (part.CFrame.p - pos2).Z)

local Two = Vector3int16.new((part.CFrame.p - pos2).X, (part.CFrame.p + pos2).Y, (part.CFrame.p + pos2).Z)

local Region = Region3int16.new(One, Two)

local terrainRegion = workspace.Terrain:CopyRegion(Region)
workspace.Terrain:Clear()
part:Destroy()
task.wait(5)
workspace.Terrain:PasteRegion(terrainRegion, Region.Min, false)

Where does the value pos2 come from?

local pos2 = (part.CFrame.lookVector * (part.Size.Z / 2)) - (part.CFrame.upVector * (part.Size.Y / 2)) + (part.CFrame.rightVector * (part.Size.X / 2))

I mean, It should work in theory. But when I went to test it in Studio, it did NOT like it.

Literally crashed my Studio each time I ran it.

It was when it was copying the region it would make studio stop responding.

Very odd, But it might just be because your code is getting the region from different vertices