You are misunderstanding how strings work.
In this line
example[2] = {"this", "is", "number2"}
Lua reads it bit by bit. It sees, {, so it knows it's making a list.
It sees ", so it knows it's starting a string. The second " lets it know that this as text is the first string. Then a ,, so it knows it's starting another thing in the list. Etc.
When it see this line:
example[1] = {script.StringValue.Value}
it sees, {, so it's starting a list. Then it sees this first and only thing in that list, script.StringValue.Value, so it grabs that value, and puts it in the list.
When you write code in a string, Lua does not run that code.
It would be a nightmare if it did -- you wouldn't be able to make strings with, say, "3 + 4" because it would immediately change itself into 7. What would you even do if you had {"this" in your StringValue? Do you just get an error for even typing that because it doesn't close the curly brace? When you chat that everything breaks because it can't handle?
The contents of the string value are the string -- and not a list.
You can see exactly that when you printed it out:
example[1] is "this", "is", "number1", which is just one string -- printing omits the quotes around strings.
You probably don't want to actually write your StringValues as though they were tables.
If you do, you should just use a ModuleScript that returns that table, rather than a StringValue.
If you want to have some structured information in a string... then come up with a simple format for yourself. E.g., if you want every word in a string, you can write that using gmatch:
local text = "This is a string!"
for word in text:gmatch("%S+") do
print(word)
end
If you need to stick with StringValues, and you have exactly three values... Just make 3 different StringValues! And give each the name that describes what it is!
That's much more friendly than a weird format in one string value.
3 comments
thx for all the info. i'm trying to make a free model that allows users who don't know scripting to be able to customize the model without editing any scripts. This method works if it only needs two infos, then i could make Name and Value into table entries. but alas, i need three infos for this particular project to function smoothly
If you need three values, just make three StringValues. If you need something more powerful, do parse the string or use a module.
Thx for advice. I was messing with trying to figure out parsing, then decided to try jsondecode and it worked! :D