Hi everyone, this is a wicked quick error and I am terrible at CFrame but here it is.
I made a system where the player can save their objects placed. However, if they save the data, then rejoin, and claim a different plot, the color, loads, same as the block, but the CFrame is off, here is how I am loading it:
I had some kind of issue where it didn’t position before and I used an exponent and fixed my issue. May it can fix yours! If not then I’m not to sure since I’m not good with CFrames either.
Maybe try using SetPrimaryPartCFrame. Thats really all I have. Don’t forget to set a primary part where you think the position is going to be at most accurate though.
I would try saving the object’s offset relative to the plot’s position.
Edit: The code below does not work if the block is at a different orientation
local plotPos = game.Workspace.Part.CFrame
local plotPos2 = game.Workspace.Part2.CFrame
local objectPos = game.Workspace.block.CFrame
local calculation = plotPos:ToObjectSpace(objectPos)
--Save here.
--------------
local data = calculation -- Your Data here.
local object = game.ServerStorage.Object:Clone() --Your object here.
object.Parent = workspace
object.CFrame = data * plotPos
With a plot system, you need to understand that there is workspace positioning and cframe, but when handling within the plot itself, it needs to be identifiable within the plot itself like a workspace within workspace
I have not attempted a plot system before, but I would probably use the middle point of the entire plot area as a reference point, and calculate objects positions based off the plot middle point for later saving/loading
Yes, sometimes it doesn’t actually exist so that’s why it gives nil. Also check the other parts that are being loaded in if their real instances/values. No reason for it to return nil if it is a “Part”
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
table.insert(plotdata,{
["Name"] = objects.Name,
["Pos"] = tostring(plot.CFrame:ToObjectSpace(objects.CFrame)),
["Color"] = {
["R"] = objects.Color.R,
["G"] = objects.Color.G,
["B"] = objects.Color.B
}
})
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)
Loading Error:
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
BrickColor works. Same as the object cloning, but not the CFrame.