how can i load in my terrain using a script?
Hello, i have made a terrain for my game and i'm currently using a plugin to save / load the terrain in manually but i don't know how to use the script to load in the terrain automatically / through a script. Their is some what of a set of instructions but its very broad and minimal and i don't understand it, help would be very much appreciated :)
-- Terrain Save & Load
-- Crazyman32
-- January 17, 2015
--[[
03 | - Keep this under ServerScriptService or ServerStorage |
04 | - Use from a Script on the server ( not LocalScript) |
09 | local terrainSaveLoad = require(game.ServerScriptService.TerrainSaveLoad) |
12 | local savedTerrain = terrainSaveLoad:Save(includeWaterProperties) |
18 | terrainSaveLoad:Load(savedTerrain) |
--]]
local TerrainSaveLoad = {
Version = "1.0.3";
}
function TerrainSaveLoad:Save(includeWaterProperties)
01 | local t = game.Workspace.Terrain |
04 | local tr = t:CopyRegion(t.MaxExtents) |
05 | tr.Name = "SavedTerrain" |
06 | tr.Parent = game.Workspace |
09 | if (includeWaterProperties) then |
10 | local waterProps = Instance.new( "Configuration" , tr) |
11 | waterProps.Name = "WaterProperties" |
12 | local function SaveProperty(class, name) |
13 | local p = Instance.new(class, waterProps) |
18 | print ( "Failed to get property: " .. tostring (err)) |
21 | SaveProperty( "Color3Value" , "WaterColor" ) |
22 | SaveProperty( "NumberValue" , "WaterReflectance" ) |
23 | SaveProperty( "NumberValue" , "WaterTransparency" ) |
24 | SaveProperty( "NumberValue" , "WaterWaveSize" ) |
25 | SaveProperty( "NumberValue" , "WaterWaveSpeed" ) |
29 | game:GetService( "Selection" ):Set( { tr } ) |
end
function TerrainSaveLoad:Load(terrainRegion)
02 | assert (typeof(terrainRegion) = = "Instance" and terrainRegion:IsA( "TerrainRegion" ), |
03 | "Load method for TerrainSaveLoad API requires a TerrainRegion object as an argument" |
07 | local xPos = -math.floor(terrainRegion.SizeInCells.X * 0.5 ) |
08 | local yPos = -math.floor(terrainRegion.SizeInCells.Y * 0.5 ) |
09 | local zPos = -math.floor(terrainRegion.SizeInCells.Z * 0.5 ) |
10 | local pos = Vector 3 int 16. new(xPos, yPos, zPos) |
13 | local waterProps = terrainRegion:FindFirstChild( "WaterProperties" ) |
15 | local function LoadProperty(name) |
16 | local obj = waterProps:FindFirstChild(name) |
17 | if ( not obj) then return end |
19 | game.Workspace.Terrain [ obj.Name ] = obj.Value |
21 | print ( "Failed to set property: " .. tostring (err)) |
24 | LoadProperty( "WaterColor" ) |
25 | LoadProperty( "WaterReflectance" ) |
26 | LoadProperty( "WaterTransparency" ) |
27 | LoadProperty( "WaterWaveSize" ) |
28 | LoadProperty( "WaterWaveSpeed" ) |
32 | game.Workspace.Terrain:PasteRegion(terrainRegion, pos, true ) |
end
return TerrainSaveLoad