Template:TerrainBuilder3DRbxPerstanceHost

-- TerrainBuilder 3D Data Perstance Host Script -- Load RbxLibraries local RbxGui = assert(LoadLibrary('RbxGui')) local RbxUtility = assert(LoadLibrary('RbxUtility')) -- local RbxStatus = assert(LoadLibrary('RbxStatus')) local RbxGear = assert(LoadLibrary('RbxGear')) local RbxStamper = assert(LoadLibrary('RbxStamper')) -- Done Loading RbxLibraries -- Link to Server Script local ServerScript = game.Workspace.TerrainBuilderScript local Player = game.Players:FindFirstChild(_G.HostName) local PlayerName = Player.Name

-- Data Persistance Keys local TerrainMap = "TerrainMap" local TerrainInv = "TerrainInv" local TerrainCom = "TerrainCom" local TerrainOth = "TerrainOth"

-- We need to wait to save Player:WaitForDataReady

local Utils = RbxUtility

-- -- Data Persistence -- --

function GetLastSavedTime local OldTime for Times = 1, RetryAttempts do     Succ, OldTime = pcall(function Player:LoadNumber(DateStamp) end) if Succ == true then Times = RetryAttempts end end return OldTime end

-- Save Functions

-- Save Map function SaveMapToDP local JSON = Utils.EncodeJSON(_G.TableMap)-- Convert the table to a string local succ, ret = pcall(function Player:SaveString(TerrainMap, JSON) end) local DataCostUsed = #JSON / 100 return succ, DataCostUsed end

-- Save the Inventory function SaveHostInvToDP local JSON = Utils.EncodeJSON(_G.TableInventory[PlayerName])-- Convert the table to a string local succ, ret = pcall(function Player:SaveString(TerrainInv, JSON) end) local DataCostUsed = #JSON / 100 return succ, DataCostUsed end

-- Save the Computer Data function SaveComDataToDP local JSON = Utils.EncodeJSON(_G.TableComputerSave[PlayerName])-- Convert the table to a string local succ, ret = pcall(function Player:SaveString(TerrainCom, JSON) end) local DataCostUsed = #JSON / 100 return succ, DataCostUsed end

-- Save Function function SaveEverythingToDP local MapSaved, MapDataCost = SaveMapToDP local InvSaved, InvDataCost = SaveHostInvToDP local CoDSaved, ComDataCost = SaveComDataToDP end

-- Load Functions

-- Load Map function LoadMapFromDP local ok, ret = pcall(function return Player:LoadString(TerrainMap) end) if ok == true and ret ~= nil then _G.TableMap = RbxUtility.DecodeJSON(ret) end return ok, ret end

-- Load Inventory function LoadInvFromDP local ok, ret = pcall(function return Player:LoadString(TerrainInv) end) if ok == true and ret ~= nil then _G.TableInventory[PlayerName] = RbxUtility.DecodeJSON(ret) end return ok, ret end

-- Load Computer Data function LoadComFromDP local ok, ret = pcall(function return Player:LoadString(TerrainCom) end) if ok == true and ret ~= nil then _G.TableComputerSave[PlayerName] = RbxUtility.DecodeJSON(ret) end return ok, ret end

-- Load Map function LoadPlayerWorldFromDP local MapSaved, MapData = LoadMapFromDP local InvSaved, InvData = LoadHostInvFromDP local CoDSaved, ComData = LoadComDataFromDP _G.ReloadMap end

--