So I need a script to choose randomly from a folder of 4 values. The Values are color names. How do I randomly choose 1 of the values?
✓ ANSWER ACCEPTED
how do i choose a random value?
2 answers
✓ Accepted answer
You should do this.
local folders = {nil, nil, nil, nil} --insert values here here
local n = math.random(1, 4)
local value = folders[n]
print(value)
math.random() picks a number between the first argument and the second argument. For example, if you do math.random(1, 2), it has a 50% chance of choosing 1 and a 50% chance of choosing 2.
@hiimgoodpack I did this, but It doesn't choose the color, it chooses nil?
local Colors = {Blue, Red, Yellow, Purple}
local n = math.random(1, 4)
local Color = Colors[n]
print(Color)
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
Blue, Red, Yellow and Purple need to be strings. local Colors = {"Blue", "Red", "Yellow", "Purple"}
thanks