I’ve been working on a plot building system recently and I’m trying to think of the best way to save it, I thought at first tables would be what I would use but then I thought that dictionaries would be better with a key being the item/block/whatever and the value would be some CFrame table. Any ideas or advice would be very helpful.
You can serialize the CFrame (info on that), perhaps with a table that contains the components of the CFrame (something like {CFrame:GetComponents()}
).
Assuming your game has the same types of blocks repeated, inside of the saved dictionary have a key that describes that certain type of block set to a table, and store the CFrames of all the blocks with that type under that table.
This is the saving part, to load you can simply loop through each key’s table, create a part of that type (perhaps have a block of each type inside of ServerStorage, and clone it) and position it in that CFrame, to deserialize the CFrame, you simply do CFrame.new(unpack(theSavedCFrame))
.
One extra thing you can do, assuming your game has multiple plots, save how far off each part’s CFrame is from a plot’s CFrame, and when loading the CFrame you would be adding the saved CFrame to the selected plot’s CFrame.
Pretty much:
{CFrame:ToObjectSpace(currentPlot.CFrame):GetComponents()} --save this
CFrame.new(unpack(savedCFrame)):ToWorldSpace(selecedtPlot) --loaded cframe