How to save a folder with many parts in it to a datastore

So I have a building system, I want to save the structures the player makes. To do so I’ve thought on having various slots that can be swapped/saved/loaded.
Now, I want so those slots are also saved to the cloud, obviosly. The problem is that I’m not sure how I’m supposed to save a folder with many parts in it?

here’s an image of the structure of it
image

I havent really tried anything because I have no idea on how to do it.
Any help is appreciated

2 Likes

you can use the instancestore module or if you want, read this How to save parts, and the idea of Serialization

you would need to “serialize” its properties.

1 Like

Essentialy you classify the object to save as whatever it is. Think of it like a custom ClassName. Inside the object your function goal is to take the location and size of the parts one by one and save them to copy back in later. Let’s say I have a Model with some parts in it. You want to save it as individual parts with their respective locations and sizes, but you want it all to be recognized as a model and not a bunch of parts, so you tell it that! Message me if you want me to show you first hand, I’m so happy to share skills with passionate people!!

Okay… Could you please explain how can I do this?
I can think of a for loop going through all the parts in it, then I can do save the values in a table. Something like this?

for I, slot in pairs(playerInfo:GetChildren()) do
     Slots['slot'..tostring(I)] -- I'm not sure if this will create a directory or not, I'm not that good with tables
     If #slot:GetChildren() <= 0 then continue end
     for i, piece in pairs(slot) do
          Slots['slot'..tostring(I)][piece.Name..tostring(i)] -- Line 6
     end

In line 6, how would I save the Size and Position here?

I don’t really understand the part of “Classname” you told me honestly. I haven’t yet got used to tables

you could do it like this:

function vectortosaveable(vector)
return {X = vector.X, Y = vector.Y, Z = vector.Z}
end

im not gonna self promote, but i made a tutorial on this

1 Like
local Slots = {}
for I, slot in pairs(playerInfo:GetChildren()) do
      local slotName ='slot'..tostring(I)
      if #slot:GetChildren() <= 0 then continue end
      for i, part in pairs(slot) do
          partInfo = {
               Size = tostring(part.Size),
               Position = tostring(part.Position)
               Color = tostring(part.Color3)
               Material = part.Material.Name
          }
          Slots[slotName][piece.Name..tostring(i)] = partInfo
     end
end

playerData[Slots]

I’ve thought about doing this…
Wouldn’t it work?

it would be harder to load it, just convert it to a table

Actually nevermind.

What about this?

local Slots = {}
for I, slot in pairs(playerInfo:GetChildren()) do
      local slotName ='slot'..tostring(I)
      if #slot:GetChildren() <= 0 then continue end
      for i, part in pairs(slot) do
          partInfo = {
               Size = {part.Size.X, part.Size.Y, part.Size.Z},
               Position = {part.Position .X, part.Position .Y, part.Position .Z},
               Color = {part.Color3.R , part.Color3.G, part.Color3.B},
               Material = part.Material.Name
          }
          Slots[slotName][piece.Name..tostring(i)] = partInfo
     end
end

playerData[Slots]

perfection. for the loading read step 2 of tutorial.

2 Likes

I think this will help you: How do i create a saving system for parts using DataStores? - #17 by OnlyJaycbee

It’s very complete, so I’d rather share it here than rewrite it myself.