Hello
I have a part and terrain around it.
I want to copy the terrain around the part, delete it and later I want to paste it at the exact same place where it was.
This is the code ,which I am using
local radius = 300
local pos = workspace.Part.Position
local region = Region3int16.new(Vector3int16.new(pos.X-radius, pos.Y-radius, pos.Z-radius), Vector3int16.new(pos.X+radius, pos.Y+radius, pos.Z+radius))
local terrainData = workspace.Terrain:CopyRegion(region)
workspace.Terrain:Clear()
task.wait(5)
workspace.Terrain:PasteRegion(terrainData, region.Min, false)
This works perfectly fine when the part and the terrain are at the center of the map, but does not work at all when the part and the terrain are 2000 studs away from the center.
The terrain does not appear at all during the Paste.
What do I miss?
You got the illusion your code was working, since the workspace.Part.Position is not related to the terrain coordinates. With a radius big enough you will copy the entire terrain and paste it back after clearing. You need to convert Part.Position to Terrain coordinates as this example:
local radius = 30
local pos = terrain:WorldToCell(workspace.Part.Position)
local region = Region3int16.new(Vector3int16.new(pos.X-radius, pos.Y-radius, pos.Z-radius), Vector3int16.new(pos.X+radius, pos.Y+radius, pos.Z+radius))
local terrainData = workspace.Terrain:CopyRegion(region)
workspace.Terrain:Clear()
task.wait(5)
workspace.Terrain:PasteRegion(terrainData, region.Min, false)
It is fine. The problem was the part. Position. Since that coordinates could not be used to calculate the region. If you replace your code with mine, will work just fine. Don’t matter where you put the Part.