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

CFrame conversion to JSON not encoding/decoding properly?

Hi guys!

I'm trying to save CFrame to a stringvalue using table and JSON encoding/decoding :)

Any ideas what I'm doing wrong? I'm not sure how to convert CFrame to a table?! I thought CFrame was already a table...

Thanks!

local position = game.Workspace:FindFirstChild(plr.Name.."Office"):GetPrimaryPartCFrame()
local HttpService = game:GetService("HttpService")
local json = HttpService:JSONEncode(position)
print(json)
plr.PlayerData.ModelPos.Value = json

It prints [nulll] unable to convert to JSON and then on decoding "Unable to parse JSON"

Thanks!

1 answer

✓ Accepted answer

The problem is that CFrames cannot be encoded by JSONEncode. Your best bet would be to store the individual components in a table, then reconstruct the CFrame when loading:

-- Saving:
JSON = HttpService:JSONEncode({position:components()})
-- Loading:
Value = CFrame.new(unpack(HttpService:JSONDecode(JSON)))

1 comment

0

Thank you very much!

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