Help with ToObjectSpace and ToWorldSpace

I’m having trouble with saving and loading a models position. I’ve looked around everywhere, asked around for help, and have gotten this far but can’t figure out what’s wrong

-- Saving
function cframeToTable(cf)
	return {cf:GetComponents()};
end

ItemData.Position = cframeToTable(PlayersInterior.PrimaryPart.CFrame:ToObjectSpace(PrimaryPart.CFrame))
print('Saving', unpack(cframeToTable(PlayersInterior.PrimaryPart.CFrame:ToObjectSpace(PrimaryPart.CFrame))))

Ok so I place a table down


And here’s the print I get from the save when I leave

[Saving -45 1.75 15.5 0 0 1 0 1 0 -1 0 0]

And now the load script

-- Loading
function tableToCframe(t)
	return CFrame.new(table.unpack(t));
end

NewItem:SetPrimaryPartCFrame(tableToCframe(CFrameData):ToWorldSpace(PlayersInterior.PrimaryPart.CFrame))				
print('Loading', tableToCframe(CFrameData))

prints this

[Loading -45, 1.75, 15.5, 0, 0, 1, 0, 1, 0, -1, 0, 0]

Can see that both prints return the same CFrame, however, the furniture item is placed thousands of studs away

and its position on the X value is way off what is being printed as well as the other values not adding up

1 Like

maybe you should change the Save system from ToObjectSpace to ToWorldSpace,
since the load script uses ToWorldSpace.

I figured it out myself

-- Saving
function cframeToTable(cf)
	return {cf:GetComponents()};
end

ItemData.Position = cframeToTable(PlayersInterior.PrimaryPart.CFrame:ToObjectSpace(PrimaryPart.CFrame))

-- Loading
function tableToCframe(t)
	return CFrame.new(table.unpack(t));
end

NewItem:SetPrimaryPartCFrame(PlayersInterior.PrimaryPart.CFrame:ToWorldSpace(tableToCframe(CFrameData)))