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}}"))()
print(loadstring("return {{1,1,1},{0,0,0},{1,1,1}}")())
worked perfectly fine for me (I did not test it in studio, I tested it in an online lua compiler ). In order to adapt this method to your code:
local textToConvert = "{1,1,1},{0,0,0},{1,1,1}"
local tbl = loadstring(("return {%s}"):format(textToConvert))()
print(tbl)
Sorry for the inconvenience.
1 Like
I can think of 2 methods atm:
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.
Loop through the string and manually check what the character and the character after is and add them to an empty table accordingly.
gertkeno
(Gert)
September 28, 2022, 4:34pm
#3
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.