Editing Script Source I think?

Hi, uh I’m trying to create a script through command bar with some lines inside it, how can I put a table inside the script?

Something like:

local testTable = {Vector.new(0, 0.5, 0), Vector.new(2, 0.5, 0), Vector.new(4, 0.5, 0),} -- Vector.new(1000, 0.5, 0)

local script = Instance.new("Script", workspace)
script.Source = game:GetService("HttpService"):JSONEncode(testTable)
local testTable = {{0, 0.5, 0}, {2, 0.5, 0}, {4, 0.5, 0}}
local script = Instance.new("Script", workspace)
script.Source = "local _table = game:GetService('HttpService'):JSONDecode('"..game:GetService('HttpService'):JSONEncode(testTable).."')"
2 Likes

Ahh yes. On the Script | Roblox Creator Documentation info article it says the property value type for Source is a string. So that means you would have to use the newline operator \n to start a new line in the string. For example, if I wanted to create a script with the starting line: -- BuilderBob25620 made this and the following line print("Success!") I’d do something like this:

Instance.new("Script",workspace).Source = "-- BuilderBob25620 made this\nprint('Success!')"

That provides me with a new script in the workspace with the source code saying:

-- BuilderBob25620 made this
print('Success!')
1 Like

Woah, fast replies! Thanks, this helped me alot, I forgot that :JSONEncode has a :JSONDecode counterpart :grimacing:

Ahh yes. On the Script.Source info article it says the property value type for Source is a string. So that means you would have to use the newline operator \n to start a new line in the string. For example, if I wanted to create a script with the starting line: -- BuilderBob25620 made this and the following line print("Success!") I’d do something like this:

I already know this but thanks for giving tips :>