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
--[[
How to use:
- Keep this under ServerScriptService or ServerStorage
- Use from a Script on the server (not LocalScript)
Example:
local terrainSaveLoad = require(game.ServerScriptService.TerrainSaveLoad)
-- Save terrain:
local savedTerrain = terrainSaveLoad:Save(includeWaterProperties)
-- Saves water properties too if "includeWaterProperties" is 'true'
-- Load terrain:
terrainSaveLoad:Load(savedTerrain)
--]]
local TerrainSaveLoad = { Version = "1.0.3"; }
function TerrainSaveLoad:Save(includeWaterProperties)
local t = game.Workspace.Terrain
-- Copy terrain:
local tr = t:CopyRegion(t.MaxExtents)
tr.Name = "SavedTerrain"
tr.Parent = game.Workspace
-- Save water properties:
if (includeWaterProperties) then
local waterProps = Instance.new("Configuration", tr)
waterProps.Name = "WaterProperties"
local function SaveProperty(class, name)
local p = Instance.new(class, waterProps)
p.Name = name
xpcall(function()
p.Value = t[name]
end, function(err)
print("Failed to get property: " .. tostring(err))
end)
end
SaveProperty("Color3Value", "WaterColor")
SaveProperty("NumberValue", "WaterReflectance")
SaveProperty("NumberValue", "WaterTransparency")
SaveProperty("NumberValue", "WaterWaveSize")
SaveProperty("NumberValue", "WaterWaveSpeed")
end
-- Set as selected:
game:GetService("Selection"):Set({tr})
-- Return the TerrainRegion copy:
return tr
end
function TerrainSaveLoad:Load(terrainRegion)
-- Ensure 'terrainRegion' is correct:
assert(typeof(terrainRegion) == "Instance" and terrainRegion:IsA("TerrainRegion"),
"Load method for TerrainSaveLoad API requires a TerrainRegion object as an argument"
)
-- Find center position:
local xPos = -math.floor(terrainRegion.SizeInCells.X * 0.5)
local yPos = -math.floor(terrainRegion.SizeInCells.Y * 0.5)
local zPos = -math.floor(terrainRegion.SizeInCells.Z * 0.5)
local pos = Vector3int16.new(xPos, yPos, zPos)
-- Load water properties:
local waterProps = terrainRegion:FindFirstChild("WaterProperties")
if (waterProps) then
local function LoadProperty(name)
local obj = waterProps:FindFirstChild(name)
if (not obj) then return end
xpcall(function()
game.Workspace.Terrain[obj.Name] = obj.Value
end, function(err)
print("Failed to set property: " .. tostring(err))
end)
end
LoadProperty("WaterColor")
LoadProperty("WaterReflectance")
LoadProperty("WaterTransparency")
LoadProperty("WaterWaveSize")
LoadProperty("WaterWaveSpeed")
end
-- Load in the terrain:
game.Workspace.Terrain:PasteRegion(terrainRegion, pos, true)
end
return TerrainSaveLoad

15 comments
and you said you are bad at scripting... ;-;
hey i put the code you gave me in a script located under ServerScriptService and "includeWaterProperties" is coming up as unknown, how do i set it to true or what do i need to do for it to be defined, thanks.
It pretty easy. You can do like this: terrainSaveLoad:Save(true) to set it to true and vice versa.
And @Ngyuenlegiahung, yes I'm bad at scripting :)
i may sound very dumb but i don't know what you mean. please take more time to help me i would be very thankful, i have this in a script: local terrainSaveLoad = require(game.ServerScriptService.TerrainSaveLoad) terrainSaveLoad:Save(true) local savedTerrain = terrainSaveLoad:Save(includeWaterProperties) terrainSaveLoad:Load(sav
I think I should re-write the answer...
yes please
i pasted that code into a script and the "includeWaterProperties" is "unknown", do i need to set it as a variable or something so that it reconizes it?
You don't need to do that. You can do local savedTerrain = terrainSaveLoad:Save(true) directly.
i get this error: 01:24:55.430 - The current identity (2) cannot Set (lacking permission 1)
I never seen this error before. Check is there any terrain in your game right now.
i want some terrain i have to be copy and pasted through a script but i don't understand how i can do that with the script that is given with the plugin. could you please create some code that i could put into a script that would do that.
yes their is terrain in my map right now, this is the code i have in the other script and i have not modified any code in the module script : local terrainSaveLoad = require(game.ServerScriptService.TerrainSaveLoad) -- require the module so we can use it local savedTerrain = terrainSaveLoad:Save(true) -- this will save the current terrain terrainSaveLoad:Load(savedTerrain) -- This will load the
Maybe the plugin out-dated...
Possibly : / . i just really want to put terrain in my game which i can clone / load. thanks for your time though