Land Save And Load Problem Please Help!

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)

(also sorry for bad grammar :frowning:)

why are you using so many cframe a simple Part.CFrame has the rotation position of the object
the error must be from the many cframes you created

1 Like

if i use part.CFrame while saving there will be an error said:

cannot store Dictionary in data store. Data stores can only accept valid UTF-8 characters.

okey i see the you cant save a single cframe

So what should i do?? i want to save the rotation too but when i load it and set it the object will go super far away

i think ther error is here

	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))

What should i do i have NO idea??

ima open Roblox studio and find a solution quickly

i think i found a solution try this out also CFrame.New is for position CFrame.Angles is for rotation

object:SetPrimaryPartCFrame(CFrame.new(v.cframex, v.cframey, v.cframez),CFrame.Angles(cframerotationx1,v.cframerotationx2,v.cframerotationx3,v.cframerotationy1,v.cframerotationy2,v.cframerotationy3,v.cframerotationz1,v.cframerotationz2,v.cframerotationz3))

Did it fix it? If yes then mark it as a solution.

Instead maybe do:

local toload
tolad = DataStore:GetAsync(script.Parent.Parent.Parent.Parent.Parent.UserId

Sorry i was afk all this time btw it gave me an error said:

Argument 3 missing or nil

It loads successfully but the problem is the object rotation

You set the components in the wrong order.

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?

The size of the table is far from the limit so don’t worry about that.

My advice would be to save the components as an array rather than a dictionary.

When saving,

local NewObject = {
    cframe = table.pack( CFrame:GetComponents() )
    name = v.Name
}

And when loading,

object:SetPrimaryPartCFrame( CFrame.new( table.unpack( v.cframe ) ) )

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.

Give that a go, and see if that helps at all.

2 Likes