Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Is there any way to convert a CFrame to a string and back again?

It seems that CFrames are lost when encoding a table to json. Is there any way to easily convert a CFrame to a string and vice versa?

1 answer

I'd use something like these two functions:

function encode_cframe(cf)
	return string.format(string.rep("%f ",12), cf:components())
end

function decode_cframe(cf)
	local tab = {}
	for s in gmatch(cf, "%d+") do
		table.insert(tab,tonumber(cf))
	end
	return CFrame.new(unpack(tab))
end

Untested, but should work.

EDIT: small fix.

This discussion is preserved as it was. New answers, comments, and votes are closed.