A mistake that I have caught is that you did not put a comma(,) or a semicolon(;) after each string. That is very important to have so you could access those strings. Another thing you must know is that if you put # before a table name, that gets the number of keys (in this case strings) in your table. The final thing you should know that if you want to get the strings in your table or access anything in the table, you would have to do Strings[Which string you want to get]. You have 3 strings, so you are able to put in between the brackets 1, 2 or 3. Here is your fixed script.
local Strings = {"line1", "line2","line3"}
local selectedIndex = math.random(1,#Strings)
local selectedString = Strings[selectedIndex]
print('Selected String is ' .. selectedString)
print('Selected Index is ' .. selectedIndex)
If you wanted to make things truly random, you would put math.randomseed(tick()) on the top of your script.
math.randomseed(tick())
local Strings = {"line1", "line2","line3"}
local selectedIndex = math.random(1,#Strings)
local selectedString = Strings[selectedIndex]
print('Selected String is ' .. selectedString)
print('Selected Index is ' .. selectedIndex)
Please accept my answer if it fixed your script. If not, please ask questions in the comments.
12 comments
Again, i did paste in your 2nd block of code into my script, it only prints one line and is not random.
What do you mean one line, as in one string
Yes, one string.
you want it to print everything in the table
oh
i understand what you mean
fixed
That still prints the same line over again.
I don't know how to fix that anymore
Randomseed does not work
I don't know actually how to make it truly random anymore
I don't know, either.