hello, I am kinda new, I mean I never scripted with terrain before.
https://developer.roblox.com/en-us/api-reference/class/TerrainRegion
Is there any way to like save it on a Table?
What I want to do is, have many maps, and to have their own terrain in their own world root.
Like this;
Is this possible?
Otherwise how can I load/unload maps with terrain, or best way?
No, you will have to create those terrains in a script, save each one as a variable and the script must generate it and remove it, that’s what i would do but might take long to understand
Uh, but how can I save many terrains then?
If I can only make 1 terrain per place
I mean I just wanna load/unload terrain basically but multiple maps/terrains
Do you mean like saving terrain in data and can be loaded, or saving different maps of terrain that will stay in the game
Not in a data, I mean not meant to save on datastore, but able to spawn/dispawn/spawn different
Yes you will have to do that all in a script so you would need to know how to make terrain in a script, and more than one terrain map is impossible, you will have to use script to somehow generate all the maps at the same time
Perhaps try taking a look at this plugin’s source code and see if you can do the same thing.
You can store Terrains in an Module, and use require to trigger module and module will loads up the terrain.
Basically, there are two very useful functions in the API:
Terrain:CopyRegion and Terrain:PasteRegion
(Usage example)
local terrainRegion = workspace.Terrain:CopyRegion(workspace.Terrain.MaxExtents)
workspace.Terrain:Clear()
wait(5)
workspace.Terrain:PasteRegion(terrainRegion, workspace.Terrain.MaxExtents.Min, true)
I suggest saving the terrain regions into serverstorage, and then loading them in when you need them.
(to load the terrain from serverstorage all you need to do is:
workspace.Terrain:PasteRegion(game.ServerStorage.YOURMAP, workspace.Terrain.MaxExtents.Min, true)
Hope I helped!
So, in TerrainRegion, how do I set the map in there?I don’t get it.
How do I check the source code?
D:
Can someone help?
Couldn’t find a solution yet
I’m not really sure, considering how you save your maps, you could try doing this,
local terrainRegion = workspace.Terrain:CopyRegion(workspace.DirtTrack.MaxExtents)
or
local terrainRegion = workspace.Terrain:CopyRegion(workspace.DirtTrack.TerrainRegion)
Yes, but the TerrainRegion in dirt track, what’s that??
I mean I can’t put the terrain there D:
Im pretty sure the terrainregion in dirt track is the terrain that spawns when you load it.
No it’s not, that terrain region is like nothing, it doesn’t exists or do anything its like I jsut added
Oh uh, that’s odd. I’ll see if I can get on my pc today and find a solution.
What are you trying to do? What kind of game are you trying to make?
If you have all the maps + terrain in the same place then you can do like this:
- For each of you map containers (like DirtTrack) put another folder which has two parts marking the extents of the map terrain.
- Modify your map loading code to copy the terrain within the marked extents for each map by using
Terrian:CopyRegion()
. - Put the new
TerrainRegion
copy in the map container so you can load it later. - Delete the copied region by using
Terrain:FillRegion()
with air. - When you want to load a new map you can use
Terrain:Clear()
to remove the old terrain and then useTerrain:PasteRegion()
with the copiedTerrainRegion
for the new map.
If you want to do this clientside then you can’t use StreamingEnabled.
Something like this:
This is an awesome tool. I mean, awesome.
BadDad2004 offered this code for loading and unloading from serverscriptservice in your own games:
Really sweet plug in - big ups to Crazyman32/Sleitnick !
His tutorials are always intelligible and well done, too.