How to insert table in the script accurately

I’m trying to insert table into new script properly, so it looks exactly like in script.

ex:

   local tab = {
   ["a"] = "1";
   ["b"] = "2";
}

and I want it to look like that in a new script I’m creating (it’s a plugin, .Source works.)

  
	local Script = Instance.new("Script", workspace)
	Script.Name = "w"
	Script.Source = "" 
        --[[
           and so script's source will be
            local tab = {
                ["a"] = "1";
                ["b"] = "2";
              }
        --]]

Is there a way to do that?
I mean I tried things like JSON and TableToString

They don’t work as I want though (table to string is close)

You can use [[]] to create a long string.

Script.Source = [[
local tab = {
    ["a"] = "1";
    ["b"] = "2";
}
]]

Yeah, I know that but… It’s not really what I want to achieve.

Even If I do that, I don’t know the content of the table

That is what you wanted though ?

Okay, here’s what I’m trying to achieve.

local t = {}
addPartsToTable(t)

createNewScriptWithSource(t)

--something like that

--[[
I don't know what parts model has and what it inserts to table,
 so I want it to do it automatically, not manually
--]]

You can use repr for this.

-- so it becomes
Script.Source = "local tab = " .. repr(t)
1 Like

Thank you! It works perfectly!