Dear DevForum,
I am working on a project where one builds their own island. These islands are made up of 4x4 BaseParts that have a set height. (For simplicity, this is an integer number.)
My grid size is 112 by 93 cells, which resolves to 10416 cells (if I have done my math correctly). I wish to store the island’s state into a datastore, which is quite possible if I keep myself to only storing the height of a cell on a set position of the cell. If I serialise this in a 1-dimensional array, I get a string length of 20833 characters, which is still well below the data size limit on a datastore value.
The problem however lies in obtaining this array, or loading from a fetched array. I’ve experimented with multiple workflows which always resulted into one of two cases:
- The script reaches a timeout state as it exceeds the maximum script execution time.
- The script takes an extremely long time to finish. (My most recent measurement being 368 seconds, that’s over six minutes.)
As you can imagine, this brings trouble when loading and I haven’t even tried to bind this to a game:BindToClose() function yet. From what I’ve read, this will certainly time out.
Is there anything I can do to prevent people having to wait this long for their island to load? Is this kind of thing simply not viable?
For reference, this is what I’m doing to load the cells:
local serializedInput = '[0,0,0,1,1,1, ....... ,3,2,2,1,0,0,0,0,0]' -- Obviously, this is way longer.
local arr = game:GetService('HttpService'):JSONDecode(serializedInput)
for i=1,#arr,1 do
local p = Instance.new("Part",workspace.TerrainCells) -- TerrainCells is a folder, which is present on startup.
p.Size = Vector3.new(4,1,4)
p.Position = Vector3.new(math.fmod(i,112),arr[i],(i-math.fmod(i, 112))/112)
p.Anchored = true
wait()
end
A side note: Players will start with a pre-built island that I can provide the serialized data for in a constant variable in a script, I can also provide a ready-made terrain for these presets. Might be able to do something with this, could I perhaps store an internally used ID of the preset, then store every change the player makes?
Another side note: The only variable property of a terrain cell right now is its height. Everything of how this cell looks is dependant on the height and the height of its neighbours.
This is quite a pickle, as I can’t move on with my scripting project should I not be able to resolve this. Any advice is welcome, I’d be happy to try it out. If you need more info, I will happily provide.