How to properly serialize tycoon,builds etc in order to save it!

Hello there!

I’m currently experiemntating with serialize plot/sanbox tycoon.
I tried to do it looks easy to do and in first phase it is
Just save object Position,BrickColor,CFrame,Name

But it is complicated when come to childrens of the object we are serializing,
Because we will need to something like this:

SaveTable = {
  TESTPART = {
      Position = {
                  X = obj.Position.X
                  Y = obj.Position.Y
                  Z = obj.Position.Z
                }
         Childrens = {
            AnotherItem = {}
            }
     }
}

But problem is when in children item is more childrens and in the children is another children
So how I can deserialize that and how I can serialize that
I already tried tutorial by @EgoMoose But I did not fully understand how should I do that

If anyone did some of these systems or have tip or idea to help me
Please comment down below!
Thanks!

While I’m not sure this would be the best approach, so far this has worked in my game. Assuming you have an index of every building/build in your game, all you would have to store is CFrame, BrickColor, and the name of the building. From that information, you can reconstruct what the player built. Of course, you’ll need to serialize the CFrame and BrickColor values, but that’s not the hard part. For CFrames, there’s plenty of modules which can serialize and deserialize CFrames for you.

A basic data structure following what you mentioned would look like this:

BuildName = {
     CFrame = "", --// The serialized CFrame would be stored as a string here
     BrickColor = "Bright red"
}

Do note that this system would be much more efficient with the amount of data being stored as apposed to saving the given data for each part. For the BrickColor part of the data, that might depend on how your game works however. If every single part’s BrickColor can be changed, that’s going to take more data than if you only stored one color and used it as a reference to color some parts. Because of that, be careful with how much you intend to save!

When deserializing this data, you just get the model representing the given build from the index of all your buildings/builds. You clone it, position it with the deserialized CFrame, then do the necessary color adjustments.

This might not help you, but i recommend checking the post on serialization:

In this post he explains how to properly use the tool.

Note: You can also check out previous “kits” in the toolbar. In this case Tycoons.