Unable to change a modulescripts .Source without using jsonencode, however I cant decode it once its there. I'm stumped

I’ll only provide relevant code but im basically trying to make a cutscene plugin, since making them by hand horribly sucks.

My current goal is to insert a table of positions into a modulescript, done by the server and accessed by the client. The reason I want to use .Source is so everything is easily available and not hidden by roblox as if i were to use a table inside the module. I’ve gotten to the point where the data is where it should be however it’s still encoded
EX:

[{"1":[-350.4974060058594,189.60598754882813,0.9551732540130615,0,0,0]},{"2":[-362.3487854003906,189.60598754882813,29.424396514892579,0,0,0]},{"3":[-375.6524658203125,189.60598754882813,61.3824462890625,0,0,0]},{"4":[-388.8741149902344,189.60598754882813,93.14337158203125,0,0,0]}]

I need this decoded and put into a table somehow, and I’m just completely stumped as to how I’m going to do that. Any help is appreciated.

Relevant code:
Server

local Waypoints = {}
table.insert(Waypoints, {[part.Name] = {
		[1] = part.CFrame.Position.X,
		[2] = part.CFrame.Position.Y,
		[3] = part.CFrame.Position.Z,
		[4] = part.CFrame.Rotation.X,
		[5] = part.CFrame.Rotation.Y,
		[6] = part.CFrame.Rotation.Z,
	}})


Cutscenescript.WaypointTable.Source = game:GetService("HttpService"):JSONEncode(Waypoints)

Client

local Waypoints = require(script.WaypointTable)

Why I can’t leave it like this

The source of a ModuleScript (or any script in general) is supposed to be valid Luau code, not JSON.
Try this:

Cutscenescript.WaypointTable.Source = `return game:GetService("HttpService"):JSONDecode('{game:GetService("HttpService"):JSONEncode(Waypoints)}')`
  1. Scripts should be wrotten on LuaU only. Not JSON. At least you need to return JSON string like this: return "JSON string here"
  2. You saved CFrames incorrectly. CFrames have 9 rotational components. What you saved is positions of CFrame and three zeroes, cuz CFrame.Rotation just nullifies position of CFrame. You either need to save full CFrame matrix, or learn quaternions to save 4 rotational components.

This didnt work, tried it before you commented but I ended up using the repr module to convert my table into a string and then reassembling the cframes.

1 Like