How to save parts, and the idea of Serialization

I think you can do that using insertservice. I think here’s how you use it.

local insertservice = game:GetService("InsertService")

local asset = insertservice:LoadAsset(--asset id)

asset.Parent = workspace
1 Like

Just store a list of all the meshes, then instead of storing mesh id, simply store an ID which references to the mesh, then when creating the parts, instead of doing Instance.new() do MeshItem[MeshReferenceID]:Clone()

I find this method to work for most peoples use cases.

Just for your information, mesh id and Id of mesh are both the same

In this case not, the ID of a mesh is any kind of reference to the real mesh object. It can be any value you want. It just needs to specifically reference to that particular mesh at all times.

something like this?

workspace.MeshPart[meshid]:Clone()

No more something like this:

local AllMeshes = { AMeshInstance, AnotherMeshInstance }

local NewMeshPart = AllMeshes[MeshReferenceId]:Clone()
NewMeshPart.Parent = workspace

1 Like

sorry if this is a dumb question, but wouldnt that make another meshpart

Yes thats the intention, its meant to copy the mesh part, but in storage instead of storing everything about the mesh part such as its ID, you only store a reference to it.

Sorry to bump this old post, but I decided to make a All-In-One solution to this problem, its stored in a optimized binary format and solves one of the issues of serialization being bulky. It currently works with99% Of instances, including their children. Along with most of ROBLOX data types.

Anyone who is looking of r a serialization method, but doesn’t want to make their own, i’d recommend looking at this!

[TLDR; Serilization module that doesnt take a ton of datastore storage. it packs everything into a singlestring]

4 Likes

You can save parts Yes, but you cant save full on models with scripts. Its sad ngl that there is currently no way still to transfer/save models with their proper hierachy…

1 Like

Is it just me, or is everyone else having this “attempt to index function with className” error?
Edit: Sorry for posting this late, but the topic is really confusing.

1 Like

What do you mean by this exactly? Because even the quick code I wrote in this article does respect the child/parent hierarchy and upon loading should preserve that.

This doesn’t really relate to the topic or the concept in any way, this is just a common issue that can be trivially solved. You’re probably mistakenly passing a function inside of the table that InitProps receives, indexing it with ClassName later results with that error.

Which is why: don’t copy paste code ignorantly, at least understand it if you don’t wanna rewrite it from scratch, a basic understanding of the code I presented should be enough to help you debug that error. If you don’t know how to debug errors in general, that’s an important skill to acquire which is why I suggest trying to do so more.

You can also just use a serializer suited for public use by other people like the one @AwesomeXForLife made.

1 Like

I fixed it a while ago, and before that I just examined the code. My mistake was that I used a :, and not a .. I was a little confused at first, but atleast I have it working. Thanks!

1 Like

YOu cant serialize and save the source code of scripts due to script identity security.

If Roblox were to give developers access to the source code in scripts during runtime, the game can easily be spoofed by exploiters. Plus, you can just store the model in ServerStorage, collect the necessary data and serialize it. And to deserialize it, you can clone the model and set it’s position and parent. It’s not even hard.

1 Like

Question. If a player has a plot with several thousand parts, each with positions, orientations, and properties, will that take up too much space? Also, what is the limit?

If I recall correctly, the limit is 2MBs I think, not sure if that changed. Yes, that can be reached easily, I scattered a bunch of possible optimizations throughout the replies of this post, but you can easily figure out stuff yourself.

I believe the datastore limit is 4 MB, not 2MB. If you compress the data by getting rid of the useless data and round the position of the object, you will not reach the limit so easily.

Simply compression or data-splitting, problem solved. Either way this tutorial taught me alot