Hello. I already made a save and load system BUT when I loaded the save all the objects that I saved went super far away and when I used the F keycode to Zoom to the object the whole world becomes black until I zoom to baseplate here is my land save/load script:
Save:
local DataStore = game:GetService("DataStoreService"):GetDataStore("LandSaveSystem1_V1")
local Land = {
}
script.Parent.MouseButton1Up:Connect(function()
local toload = DataStore:GetAsync(script.Parent.Parent.Parent.Parent.Parent.UserId) or Land
print(toload)
table.clear(toload)
for i,v in ipairs(script.Parent.Parent.Parent.Parent.Land.Value:GetChildren()) do
if v:FindFirstChild("SaveAble") then
local NewObject = {
cframex = v.PrimaryPart.CFrame.X,
cframey = v.PrimaryPart.CFrame.Y,
cframez = v.PrimaryPart.CFrame.Z,
cframerotationx1 = v.PrimaryPart.CFrame.XVector.X,
cframerotationx2 = v.PrimaryPart.CFrame.XVector.Y,
cframerotationx3 = v.PrimaryPart.CFrame.XVector.Z,
cframerotationy1 = v.PrimaryPart.CFrame.YVector.X,
cframerotationy2 = v.PrimaryPart.CFrame.YVector.Y,
cframerotationy3 = v.PrimaryPart.CFrame.YVector.Z,
cframerotationz1 = v.PrimaryPart.CFrame.ZVector.X,
cframerotationz2 = v.PrimaryPart.CFrame.ZVector.Y,
cframerotationz3 = v.PrimaryPart.CFrame.ZVector.Z,
name = v.Name
}
table.insert(toload, NewObject)
end
end
print(toload)
DataStore:SetAsync(script.Parent.Parent.Parent.Parent.Parent.UserId, toload)
print("done")
end)
Load:
local DataStore = game:GetService("DataStoreService"):GetDataStore("LandSaveSystem1_V1")
local Land = {
}
script.Parent.MouseButton1Up:Connect(function()
local toload = DataStore:GetAsync(script.Parent.Parent.Parent.Parent.Parent.UserId)
print(toload)
for i,v in ipairs(toload) do
local object = game.ReplicatedStorage.Objects:FindFirstChild(v.name):Clone()
print(object.Name)
object.Parent = game.Workspace
object:SetPrimaryPartCFrame(CFrame.new(v.cframex, v.cframey, v.cframez,v.cframerotationx1,v.cframerotationx2,v.cframerotationx3,v.cframerotationy1,v.cframerotationy2,v.cframerotationy3,v.cframerotationz1,v.cframerotationz2,v.cframerotationz3))
end
end)
In your code, x1 = R00, x2 = R10, x3 = R20, etc. through z3 = R22.
Note the order of components as part of the CFrame constructor: CFrame.new ( number x, number y, number z, number R00, number R01, number R02, number R10, number R11, number R12, number R20, number R21, number R22 )
Specifically that it goes R00, R01, R02, and in your code you enter them as R00, R10, R20.
To correct it, change the components order to be x1, y1, z1, x2, y2, z2, x3, y3, z3.
To prevent future confusion, I strongly recommend renaming the components to their R number rather than x1,2,3.
It still not working I think I know the problem. in the table, there is something called cframerotationx1 right? but when I print it, it prints “nil” I think it’s because it cants save a big table what should I do?
That way you eliminate the need to worry about any naming and rely on the fact that arrays retain their order, and that GetComponents outputs components in the same order as the new constructor.