How would I clone Terrain through script for my Round Based System?

Does anybody know how you would go about cloning terrain since I’m trying to clone terrain for my round based system and I haven’t found any source to really help me

2 Likes

This might help

Thanks but also how would I copy the terrain my builder made for me?

If its normal roblox terrain, then that code should copy it

Well he gave me the rblx file with the terrain so???

so you want to copy the terrain in studio and not ingame?

I want to do both since I need the terrain and also I need to clone it ingame during the round based system.

For both Studio and in game, CopyRegion/PasteRegion are what you’re looking for. Use CopyRegion if they gave you a Studio file and then parent the TerrainRegion returned from CopyRegion to ServerStorage. Take that instance and put it in your game. When the round needs to use that terrain, use PasteRegion to put it in the Workspace. The Clear method of terrain will rid of any terrain that you don’t need after a match ends.

So when I press play and run the code to take the terrain I can just send the terrain to server storage then clone it?

I am having a hard time understanding.

Please be patient for responses, avoid double responding or bumping threads. Contain any small amount of content in a previous reply. I saw your reply and was typing a response.


You don’t need to use the play option.

If you need to grab terrain at any point in time, be it in Studio or at run time, use CopyRegion. For example, if you have a map on a separate place file, then use CopyRegion to get the terrain and then parent the returned object so you have an instance you can carry into other project files, such as your main place file. Run this in the command bar:

local terrainRegion = workspace.Terrain:CopyRegion(workspace.Terrain.MaxExtents)
terrainRegion.Parent = game:GetService("ServerStorage")

Now look in ServerStorage for an item called TerrainRegion. This is what you want. Copy and paste it to your game file. You can have both the map parts and terrain in one folder and then change your handler such that it pastes if it reaches a TerrainRegion or parents a map. Example hierarchy:

<Folder> map_west_forest
    <TerrainRegion> MapTerrain
    <Model> Map

Then if you need to load in the map, in whatever way you do that:

local selectedMap = ServerStorage["map_west_forest"] -- Or whatever

-- Apply map
selectedMap.Map.Parent = workspace
workspace.Terrain:PasteRegion(selectedMap.MapTerrain, workspace.Terrain.MaxExtents.Min, true)

-- Remove map
workspace.Map:Destroy()
workspace.Terrain:Clear()
8 Likes

I copied it and pasted it into workspace but it didn’t show the terrain

I figured it out thanks for your help!

Hey Colbert. :wave:

I’ve been trying to do this, but whenever I PasteRegion in a new game’s terrain, the terrain doesn’t change, no errors though.

I’ve tried using crazyman32’s plugin same result.

Could you show your code? Make sure you are referencing your terrainregion. You could try running your script in the command bar, or maybe add a wait in your script.

1 Like

Where do you put the script? Do you have the folder hierarchy in workspace or server storage or both?

Feel free to structure this in any way you want. The point to make is that this should be run on a server environment and how to use the relevant APIs to resolve the problem outlined in the OP.