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

how do i choose a random value?

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?

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)

2 comments

0

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

0

thanks

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