Datastores and serialization help

SOOOOO
Im currently trying to save everything in a folder- I know that there is another post about this but it was not well documented and im having trouble understanding.
ALL IM TRYING TO DO IS
When the player leaves - a folder in workspace (game.Workspace.Walls) -children are saved inside datastore then loaded again when the player joins. NOTE- The parts in the folder Walls are parts.

Thank you and kudos to the person that solves this!

Is it just square parts or is there round/cone parts?

See below.

It’s the answer

If you wanted to be really inefficient you could make a general-purpose function to serialize an instance and all of its children with all of their properties.

For your use case it sounds like you just need to compile a list containing data about each part in the folder. For example, lets say you wanted to save their name, cframe, size, shape and color assuming they are all baseparts.

To serialize it you would just do something like

local folder -- the folder you referenced
local t = {}
for _, child in ipairs(folder:GetChildren()) do
    if not child:IsA("BasePart") then
        continue
    end
    local data = {}
    data.Name = child.Name
    data.CFrame = child.CFrame
    -- and so on for every property you care about
    table.insert(t, data)
end

Some properties may not be serializable by httpService:JSONEncode or DataStoreService in which case you would have to write handlers for those. Additionally you could optimize properties like CFrame by only using 3 vectors, 1 for position and 2 for direction instead of the 4 that are held in the CFrame datatype.

Alright i’ve made a module for this if you want to check it out

1 Like