local cf = CFrame.new(0,50,0);
function cframeToTable(cf)
return {cf:GetComponents()};
end
function tableToCframe(t)
return CFrame.new(table.unpack(t));
end
-- Both print 50.
print(cframeToTable(cf)[2]);
print(tableToCframe(cframeToTable(cf)).p.Y);
The script below will add your cframes to a table. All you have to do is datastore it yourself.
The reason why I didn’t datastore it is because I didn’t learn datastoring yet.
local CFrameData = {}
local DataStoreService = game:GetService("DataStoreService")
local Data = DataStoreService:GetDataStore('Data')
function AddCFrameToTable(Table,Parts)
for _, v in pairs(Parts:GetDescendants()) do
if v:IsA('BasePart') then
table.insert(Table,#Table+1,v.CFrame.Position)
end
end
end
function PrintTable(Table)
for _, v in pairs(Table)do
print(v)
end
end
AddCFrameToTable(CFrameData,workspace.Parts)
wait(1.040542562456)
PrintTable(CFrameData)
Just as with Color3 and Instances, CFrame is a UserData value and cannot be directly saved to a DataStore.
I’d suggest using @Nucl3arPlays’ method for serializing (turning into a table that you can then store) and deserializing (converting into an actual CFrame)
There are compression modules that allow you to compress string, meaning if you JSON Encoded a table, then compressed it, it would compress into the datastore under its character limit. I wouldn’t call it useless since you would be able to compress it and store it successfully.
I still JSON Encode because I do not know how big my tables can be and it could most likely corrupt due to the table not fitting in a certain character limit. Plus you can only store color3 values in JSON Encoded tables, you’d have to store color3 values as numbers in a table for a datastore. But, you do you.
The same problems you raised for tables are applicable to JSONEncode. JSONEncode bloats the amount of characters you use, thus expanding the size required to fit into a DataStore. Malformed or otherwise unacceptable characters will result in JSONEncode failing and thus can be “corrupted”.
You should store Color3 values in their individual RGB values, not the raw datatype - again, thats more bloat to your DataStore unnecessarily and in addition you’re now sending over an unsupported datatype to DataStore servers.
Is there any way to add more “cframe values” to the cf variable. I was attempting to convert a table then convert that table into regular values using table.concat and separating them with commas but that could not work because I believe it does not support values. Also, I tried defaultios module but it has many inaccuracies and incorrectly converts the cframe position by a long shot.