Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 8 years ago

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

Log in to vote
0
Answered by 8 years ago

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.

Ad

Answer this question