String to Table

Hello,
So basically I want to make this string: “{{{0, 1, 0}, {1, 3, 0}, {217, 140, 255}, {71, 24, 166}, {19, 0, 114}}}”, I want to make it a table.
Because I need the player to input a table but in a TextBox, so it becomes a table.

Thanks in advance.

Edit:
I just found out that I can do this:

loadstring(("return {%s}"):format("{{0, 1, 0}, {1, 3, 0}, {217, 140, 255}, {71, 24, 166}, {19, 0, 114}}"))()

Sorry for the inconvenience.

1 Like

I can think of 2 methods atm:

  1. Use string:Split(", ") but the player’s input has to be in the format “{x,y,z}, {x,y,z}” or similar such that the table can be split twice.
  2. Loop through the string and manually check what the character and the character after is and add them to an empty table accordingly.

If you are using player input that sound very scary! Make sure players cannot run just any code, or at least keep it in a local script.

The simplest way I can think of to encode really any data into a string and back is to use HTTP service’s JSON encode and decode functions.

https://developer.roblox.com/en-us/api-reference/function/HttpService/JSONDecode

https://developer.roblox.com/en-us/api-reference/function/HttpService/JSONEncode

1 Like