I’ve created my module for saving objects!
But what if we want to save models? Should we check if the type is a primarypart and then say that r = {CFrame}
? How do we do that?
This is indeed a certain section of serializing that I haven’t dabbled, which is saving instances. In reality I would make saving instances generic, that way I can simply list the PrimaryPart to be saved, and I would utilize this to save any other instance property, such as Part0
and Part1
of welds.
I explain how I do this here
Hey, I have a question. How do I save models? Because I want to save a player’s character in-game using datastore but I don’t know how because inside the character there are other things not only baseparts like special meshes, motors, animations, cloths, hats, pants, textures, and a lot of others. Please help. Thanks!
You can loop through the character, then serialize them and save them.
How? I mean the serializing part. I know how to looop.
ok let me read it againnnnnnnnnnnnn
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
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
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]
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…
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.
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.