Save a model the player builds and load it later

I want to save an arbitrary model that a player built in my game and load it latter when the player comes back.

Is this currently possible?

I think right now the state of the art is I would need to write my own model serializer, then save to a DataStore, breaking up my binary data into 64kb pages (limit on the size of a value in a DataScore key value pair?) Either that or build my own backend and do HTTP post to it?

Has anyone written a nice abstraction layer over the DataStore backend to make it look more like a file system for developers who want a file system?

6 Likes

Most if not all games with user-generated content serialize instances and save it to a DataStore. If the size exceeds the maximum value size then the data should be broken up and saved into multiple keys. This should only be used if the assets being loaded are uniquely created per player.

I’ve never actually used a serialization module myself but you may be able to find some useful information here.
https://devforum.roblox.com/t/binary-file-format/10669/68

3 Likes

Here’s a key-based abstraction layer.

Serializing binary data wasn’t really worth until recently with the bit32 library. Generally even “binary” → base64 is significantly more expensive than just packing it into JSON.

You can serialize your instances directly (i.e. try all the properties), but I’d recommend against doing this, and instead serialize into a middleish abstract layer where you control the properties that are serialized.

Building your own backend isn’t horrible, but then you’re paying for servers, and you have to setup scaling and maintenance.

4 Likes

All things considered, if you have a game that has no profit and you’re paying for servers, something is seriously wrong. Typically, the only thing I’ll scale out myself is database handling. Even then, the pipeline is purely in Rbx lua and no web server is used.

For this scenario, Anchored, CanCollide, CFrame and BrickColor properties would suffice. You could accomplish this by iteration or recursion. I do agree that storing every property is both wasteful and inefficient.

Not a huge detail, but I’m fairly certain the value size limit in datastores is now a bit over 256kb (should be 260k).

i feel like we have API for this :thinking:

I haven’t used it, I’ve not heard great things about it… but maybe it’ll work for you?

I believe this is the closest API available for instance serialization, but it only has a very specific use case.
The ideal solution would be to save the instance as a model in the owner’s inventory, and then load it back later using InsertService.

1 Like

That would work if I could create a second Workspace in my game as it’s running to just save the parts of the place that I want.

Or I could tag the parts I want, and on load, strip out everything else.

That API is so old and unused though I have no idea if it still even works.

2 Likes

I’ve been testing it some recently and it still seems to function fine. Only issue is this. CreatePlaceInPlayerInventoryAsync Prompt Clips the Yes or No Buttons

Your most reliable option at the moment is likely to save every individual instance present in the model just by className to save space, and then when properties of the instance have changed to something other than ‘default’, mark those changes. With this method most decently sized models could be saved with a single dataStore

That being said, an api along the lines of ‘CreateAssetInPlayerInventoryAsync’ would be a good feature request, considering that roblox’s built in asset saving system can save huge models across games, and synergizes with insertService