Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to randomly print a string.?

I was just testing some stuff for a project and I got confused with randomly printing strings. The problem that I get is that it is printing its table value/order (Ie. [1], [2] etc) How would I make it print the string

local test = {

"Test1",

"Test2"

"Test3"

}

local random = math.random(1, #strings)

print(random)

1 answer

✓ Accepted answer

You are very close! First thing, you messed up your table. You have to put a comma after each index, and you forgot one after the 2nd. Secondly, when trying to get a random value from a table, you have to first index the table!

local test = {"Test1","Test2","Test3"}

local random = test[math.random(#test)] -- The # operator represents how many INDEXES (values) are inside the table!.
print(random)

1 comment

0

Thanks :D

This discussion is preserved as it was. New answers, comments, and votes are closed.