You just loop through parts and serialize their CFrame relative to the plot
parts
should be a list of all the parts you want to save (e.g.,plotFolder:GetChildren()
)- this assumes you’re saving per-player using their
UserId
local function getRelativeCFrame(part, plotBounds)
return plotBounds.CFrame:ToObjectSpace(part.CFrame)
end
local function serializeCFrame(cf)
return {cf:GetComponents()} -- gives 12 values: X, Y, Z, rotation matrix
end
(Understanding CFrame with Matrices!)
local function savePlotParts(player, plotBounds, parts)
local dataToSave = {}
for _, part in ipairs(parts) do
table.insert(dataToSave, {
partType = part.Name, -- or a tag or type or somthing like that
relativeCFrame = serializeCFrame(getRelativeCFrame(part, plotBounds)),
color = {R = part.Color.R, G = part.Color.G, B = part.Color.B}
})
end
local DataStoreService = game:GetService("DataStoreService")
local ds = DataStoreService:GetDataStore("PlotData")
local success, err = pcall(function()
ds:SetAsync(player.UserId, dataToSave)
end)
if not success then
warn("Failed to save plot data:", err)
end
end