local PartsToSave = {}
local Plots = workspace.Plots
local SaveManager = {}
function SaveManager.Sterilize(player: Player)
local PlayersPlot = Plots:WaitForChild(player.Name .. " Plot")
local Objects = PlayersPlot.Objects
for _, Object in ipairs(Objects:GetChildren()) do
table.insert(PartsToSave, {
Object.Name,
Object.Hitbox.CFrame.Orientation.X,
Object.Hitbox.CFrame.Orientation.Y,
Object.Hitbox.CFrame.Orientation.Z,
Objects.Hitbox.CFrame.Position.X,
Objects.Hitbox.CFrame.Position.Y,
Objects.Hitbox.CFrame.Position.Z
})
end
end
function SaveManager.SaveParts()
end
return SaveManager
the main issue with your code is that you’re mixing up Object.Hitbox and Objects.Hitbox you got a typo there that’s gonna mess everything up.
Also like, you’re saving the position data in a pretty inefficient way and your PartsToSave table is global which means it’s gonna get messy if multiple players are saving at the same time
Try this code:
local PartsToSave = {} -- maybe make this per player?
local Plots = workspace.Plots
local SaveManager = {}
function SaveManager.Sterilize(player: Player)
local PlayersPlot = Plots:WaitForChild(player.Name .. " Plot")
local Objects = PlayersPlot.Objects
local playerData = {} -- separate table for this player
for _, Object in ipairs(Objects:GetChildren()) do
-- fixed your typo here bro
table.insert(playerData, {
Name = Object.Name,
CFrame = Object.Hitbox.CFrame, -- save the whole CFrame instead of splitting it
-- etc.
})
end
PartsToSave[player.UserId] = playerData -- organize by player
return playerData -- return it so you can use it right away
end
function SaveManager.SaveParts(player: Player)
-- actually save to datastore here
end
return SaveManager
I will add that if this is for datastore purposes, you can’t store userdata data types like CFrames in them, and you have to store the components of the CFrame instead (which you can get by calling :GetComponents())