Convert string to CFrame (or other different possible solution)

So, I’m having the problem with datastores and it gives the error 104. By searching about it my guess is that you can’t store CFrame values, but I need them. So I tried converting a CFrame value to string (which works) but when unconverting with tonumber() it turns into nil. Any fix?

Code example:

local tab = workspace.Part.CFrame
print(tab) --prints Cframe

local tab2 = tostring(tab)
print(tab2) -- prints CFrame as a string

local tab3 = tonumber(tab2)
print(tab3) -- prints nil

Output:
2851.00806, 708.031738, 2138.79321, 1, 0, 0, 0, 5.96046448e-08, 1, 0, -1, 5.96046448e-08
2851.00806, 708.031738, 2138.79321, 1, 0, 0, 0, 5.96046448e-08, 1, 0, -1, 5.96046448e-08
nil

you would have to convert the string into a bunch of individual variables and then put those values into CFrame.new(), which you can do with string.split() and then unpacking those values from that table.

luckily for whatever reason, you can actually create cframes using strings, so CFrame.new(“12”, "34, “45”) actually works, meaning you dont have to convert each string into a number and you can use the strings directly

local str = "1, 2, 3" -- stringified cframe
local cefra = str:split(", ")
CFrame.new(unpack(cefra))
2 Likes

is there a way to do it with dictionaries? because in datastores you cannot use tables and dictionaries mixed, im using dictionaries. you can’t just do Dictionary[“CFrame”] = string:split()

you should only store the actual string in the datastore
Dictionary["CFrame"] = "1.23, 34.5, 4.56...."
and use string.split() only after retrieving it again to create a new CFrame

Oh alright thank you didn’t think of that lol

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.