local Data = {
['Name']=objects.Name,
["Pos"] = tostring(plot.CFrame:ToObjectSpace(objects.CFrame)),
["Color"] = {
["R"] = objects.Color.R,
["G"] = objects.Color.G,
["B"] = objects.Color.B
}
}
for i,v in pairs(Data) do
plotdata[i] = v
end
Got more progress, I think it works, but, now when cloning the object, it says “Argument 1 missing or nil” so the name apparently probably isn’t saving.
local loadedmodel = game.ReplicatedStorage.BuildableObjects:FindFirstChild(saved['Name']):Clone()
if loadedmodel then
print(saved.Pos)
loadedmodel.BrickColor = BrickColor.new(saved['Color'].R,saved['Color'].G,saved['Color'].B)
loadedmodel.Parent = plotbeingviewed
loadedmodel.CFrame = tonumber(saved.Pos) * plotbeingviewed.CFrame
end
game.Players.PlayerRemoving:Connect(function(player)
local plot = game.Workspace.Plots:FindFirstChild(player.PlotOwned.Value)
local plotdata = {
}
if plot then
if game.Workspace.Plots:FindFirstChild(player.PlotOwned.Value) then
for i, objects in ipairs(plot:GetChildren()) do
if objects:IsA("BasePart") and objects.Name ~= "Box" then
local Data = {
['Name']=objects.Name,
["Pos"] = tostring(plot.CFrame:ToObjectSpace(objects.CFrame)),
["Color"] = {
["R"] = objects.Color.R,
["G"] = objects.Color.G,
["B"] = objects.Color.B
}
}
for i,v in pairs(Data) do
plotdata[i] = v
end
end
end
end
end
player.PlotOwned.Value = ""
local id = "Player_" .. player.UserId
local success, err = pcall(function()
plotstore:SetAsync(id,plotdata)
end)
if success then
print("saved")
else
print("no")
print(err)
end
end)
If this doesn’t work, it most likely your datastore script
Oh found the issue, didn’t realize you had multiple datas you were saving. Now when you are adding the parts loop through the plotdata first then you can index each of it.
for i,v in pairs(saved) do
local loadedmodel = game.ReplicatedStorage.BuildableObjects:FindFirstChild(v['Name']):Clone()
if loadedmodel then
print(v.Pos)
loadedmodel.BrickColor = BrickColor.new(v['Color'].R,v['Color'].G,v['Color'].B)
loadedmodel.Parent = plotbeingviewed
loadedmodel.CFrame = tonumber(v.Pos) * plotbeingviewed.CFrame
end
end
Does the CFrame save correctly? Maybe the issue stems from how it’s being applied?
How much “off” is the CFrame? Is it a slight deviation/rotation or is it literally loading on the wrong side of the map?
Note that CFrame has some very exclusive math operations (because they’re being represented with matrices or quaternions or some other weird mathematical data structure that I’m not qualified to talk about) so if you’re not careful you’ll end up making silly mistakes, for example, cframe1 * cframe2 is NOT the same as cframe2 * cframe1
Furthermore, I’m not exactly sure why it’s doing this compound assignment; what is cube.CFrame before you try to multiply it with plot.CFrame? What and why is there a pre-set CFrame for the cube? Ideally, it should be the other way around where the object’s position is an offset of the plot, so something like
cube.CFrame = plot.CFrame * placementOffset --placementOffset being a CFrame calculated prior to saving
local base = workspace.Plot.Base
local loadBase = workspace.LoadPlot.Base
for _, p in pairs(workspace.Plot:GetChildren()) do
if p.Name == "Base" then continue end
local partCFrame = base.CFrame:ToObjectSpace(p.CFrame) -- save this
local loadPart = p:Clone()
loadPart.CFrame = loadBase.CFrame:ToWorldSpace(partCFrame) -- load like this
loadPart.Parent = workspace.LoadPlot
end