Problem with json encoding cframes with :GetComponents()

I’m making a replay system and trying to save CFrames into it’s own each keyframe table, but when I json encode it, it disappears from the dictionary. I’ve searched around and wondering if there’s an alternative or what I am doing wrong? Can I save tables without encoding into datastores?

	-- how i'm saving the cframes initially in a heartbeat
local cf = {char.HumanoidRootPart.CFrame:GetComponents()}
keyframes[plr.Name][c] = cf

-- later on
local enReplayData = HttpService:JSONEncode(replayData)
print(replayData) --[1] = 5.767, ["test2-easy"] =  ▼  { [0] =  ▶ {...},[1] =  ▶ {...},[2] =  ▶ {...}, etc
print(enReplayData) --[1] = [5.767]

Am I being stupid?

2 Likes

It looks like you have a 0-index in test2-easy. That could be part of the issue. Also, mixed tables (i.e. tables with both number and string keys) could also be a problem.

:GetComponents returns 16 numbers, most of which aren’t necessary in the vast, vast majority of cases. Just save the Position and :ToOrientation.

2 Likes

Hey so i tested it, Seems like

{
       [2] = 5.767
	["test2-easy"] = {
		[0] = "Hi1",
		[1] = "Hi2",
		[2] = "Hi3"
	},
}

Works, But

{
	[1] = 5.767, 
	["test2-easy"] = {
		[0] = "Hi1",
		[1] = "Hi2",
		[2] = "Hi3"
	},
}

Doesnt, Not sure why. But what id do is change the number keys to strings with the same number, because after encoding and decoding,

[1] = “value”

equals

[“1”] = “value”

1 Like

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