What's the Best way to do this?

Basically I’m trying to make a generated code script while passing a table for the generated script to use.

Here is my Current script below.

local CurrentTable = {}
GeneratedScript.Source = [[ local Table = ??? ]] 

What’s the best way to make Table = to the Current table?

If it’s a modulescript and you want to use it in your plugin you could do this

local CurrentTable = {}
GeneratedScript.Source = [[
local Table

function init(t)
    Table = t

local requiredGeneratedScript = require(GeneratedScript)

Otherwise you can use JSON encode and decode
(or write your own encode and decode function that doesn’t use the HttpService)

1 Like

it’s not a module script its a local script.

You can use JSON in the HttpService to encode and decode.

Or edit something like this to convert your object to valid lua code, but that won’t work for functions and such.

Oh, could you give me an example using JSON, I’ve never used it before.

local HttpService = game:GetService("HttpService")

local CurrentTable = {}
GeneratedScript.Source = [[
local Table = game:GetService("HttpService"):JSONDecode(']] .. HttpService:JSONEncode(CurrentTable) .. [[')

-- more code


A table like {a = 2, b = {2,3}, c = {d = 3, e = "4"}}
becomes {"a": 2, "b": [2,3], "c": {"d": 3, "e": "4"}}
Like lua tables but javascript


Sadly it acts like it’s null (nil)

Generated Script Table



local Table = game:GetService("HttpService"):JSONDecode(']] .. game.HttpService:JSONEncode(Cameras) .. [[')

Encoding and decoding like this only works for strings, numbers, booleans and tables (with the previous as keys and/or values)

You can however convert your part into a string using :GetFullName(), then you just have to find a way to convert "Workspace.Part1" to an actual part.

Well, Is there anyway to get the Instance?
Getting the name might be very inefficient as maybe someone already has a part named “Part1” In his game.

What is the part used for?
Because there are tons of ways to get the instance, you just have to make a way for the client to tell them apart.

Wait, Can’t I use loadstrings?

Not on the client, and that would be the same as parsing "Workspace.Part1" to find the right part.

Well it’s basically a cutscene system, the Player presses capture it generates a part and put’s it into a table.

Then clients can share parts right?

Also then you could just put those parts into a folder and do something like this in the client script:

GeneratedScript.Source = [[
local Table = game.ReplicatedStorage.Cutscenes.Cutscene1:GetChildren()

-- order by name
table.sort(Table, function(a, b)
    return tonumber(a.Name) < tonumber(b.Name)
1 Like

Ok, I tried this

		local OrderedCutsceneFolderVar = CutsceneFolderVar:WaitForChild("CutsceneCameras"):GetChildren()
		table.sort(OrderedCutsceneFolderVar, function(a, b)
			return tonumber(a.Name) < tonumber(b.Name)

and at this line it errors

local Table =']] .. OrderedCutsceneFolderVar .. [[


attempt to concatenate table with string  

You can only put strings, numbers, booleans and tables inside a script like this. So you’ll have to do the :GetChildren() and sorting on the client

1 Like

Same error.

local Table =']] .. CutsceneFolderVar:WaitForChild("CutsceneCameras"):GetChildren() .. [[

		table.sort(Table, function(a, b)
			return tonumber(a.Name) < tonumber(b.Name)

CutsceneFolderVar:WaitForChild("CutsceneCameras"):GetChildren() returns a table of Instances.

Instances are not strings, numbers, booleans nor tables.

You have to do CutsceneFolderVar:WaitForChild("CutsceneCameras"):GetChildren() on the client.

I did do it on the Client.

Only the green is being done on the client.
CutsceneFolderVar:WaitForChild("CutsceneCameras"):GetChildren() is being done in your plugin, and it’s trying to put it’s result into the client script.