Saving a workspace's instance to a specific server without using tables

Hello, I’m developing a game similar to Rust or Roblox’s “Lost” and I need a way to save structures to a datastore from the workspace, i have folders in my workspace, being World > Structures > Walls, Foundations, Floors

Theo nly problem i sthe datastore, my game will hav e a set amount of servers and the information inside them will save according to their always the same privateserverid with reserveserver, but heres the issue.

I cannot :GetChildren() On a datastore.
I cannot go local lists = ds:GetAsyncChilderen()

and then do something like for i,v in pairs (lists) do
to save and load data.

So, to combat this i have to stuff everything into a single key, but this will be messy and turn out stuff like

local s, e = pcall(function()
    dss:SetAsync("Structures", data.Name.."-"..rotX)
    dss:SetAsync("Structures", data.Name.."-"..rotY)
    dss:SetAsync("Structures", data.Name.."-"..rotZ)
    dss:SetAsync("Structures", data.Name.."-"..posX)
    dss:SetAsync("Structures", data.Name.."-"..posY)
    dss:SetAsync("Structures", data.Name.."-"..posZ)
    dss:SetAsync("Structures", data.Name.."-"..HealthLeft)
end)

And i’d need to figure out a way to have custom name sets for each entry to stop conflicting names, this is all very odd and complicated and seems very difficult to do for me, so any help would be great, I wish we could store dictionaries in datastores.

Extra note: Would using httpsservice with an out of roblox database be feasable, and if so, how?

Alright,
well everything in roblox’s datastores are stored as strings. Lua tables are internally converted to and from a JSON-format string when setting/ retrieving data. So what’s actually in the datastore is not a table.
Also note a difference between roblox userdata and lua datatypes. Roblox userdata includes any type of Instance (ex. Part, Color3, ScreenGui, Vector3). Lua datatypes include string, boolean, number, table.
You aren’t able to store userdata in roblox datastores. But you can store defining values of an instance. So look into creating a lua table of the values which make up an instance.

So something like:

part_data = {
    Name = part.Name,
    Size = {part.Size.X, part.Size.Y, part.Size.Z},
    Transparency = part.Transparency,
    ClassName = part.ClassName,
    Color = {part.Color.R, part.Color.G, part.Color.B}
}

Do not set individual keys per value, it is incredibly inefficient. You’ll quickly expend the datastore request limit, and if any of your :SetAsync or :GetAsync calls fail then its hard to handle. You won’t know which request failed, what data was saved, what wasn’t. You’ll have to retry it all again.

i was thinking somethingl ike a json encoded

datastore > key >

structures = {
ThisWall = {
xpos, ypos, zpos, xrot, yrot, zrot, hp, ownerid
}
}

You can use a dictionary in a datastore. Just make sure all your keys are strings or all your keys are numbers.

This is doable, using something like AWS S3 for storage and something like AWS API Gateway to field requests, but it would likely end up costing money and seems a bit pointless. This should be completely doable with datastores regardless.

2 Likes