How do I convert a string to another value?

Sorry for the poorly explained name of the topic, but if you didn’t understand, here’s an example

Let’s say I have a table, in a string?

local tableinstring = "{'freerobuxsucks'}"

Now, I want to convert it to an actual table.

local tableinstring = {'freerobuxsucks'}

You got it, change string to another type of value. Now, any answers?

Try table.pack(values): table

You can use HttpService:JSONDecode to handle this:

local str = "{[\"value\",\"another value\"]}"
local data = game:GetService("HttpService"):JSONDecode(str) -- converts to a table

Just another thing, is there a way to do it without those slashes etc?

Yes, I just used the backslashes because I used the double quotes (") inside the string; you can do this as well:

local str = "{['value','another value']}"
local data = game:GetService("HttpService"):JSONDecode(str) -- converts to a table

yes but there is this thing,can you remove it too?

I assumed you wanted to decode a JSON-like string, well you need to have the brackets in order for it to be decoded properly. However, you can try to utilize string patterns or any of the previously provided solutions to remove the curly braces ({})

how about maybe I would use some string.gsub so I can replace the “{” with “{[”

Would it work ?

It should work:

local newStr = string.gsub(str, "{", "["):gsub("}", "]")
local data = game:GetService("HttpService"):JSONDecode(newStr)

This JSON might be formatted incorrectly, but it should give you an idea of what to do

ok thx

Finally a valid usecase for table.create().

local tableinstring = "{'freerobuxsucks'}"
local stringintable = table.create(1, tableinstring:gsub("[{}']", ""))
print(stringintable[1])

Here’s a version which will work if the string table contains multiple values.

local tableinstring = "{'freerobuxsucks','freerobuxsucks2'}"
local stringintable = tableinstring:gsub("[{}']", ""):split(",")
print(stringintable[1], stringintable[2])

Not sure why the provided solution stacked multiple calls to string.gsub().