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

How can I pick a random color out of a table?

This is what I have

local Player = game.Players.LocalPlayer
local Remote = game.ReplicatedStorage.Network.Server.RemoteEvent
math.randomseed(tick())
local Colors = {"Red","White","Black"}
local Choosen = Colors[math.random(1,#Colors)]
local a = BrickColor[Choosen]

But when I print it it comes out with "fucntion: 40A239F0"

This is the new one, but prints the same value each time.

local Player = game.Players.LocalPlayer
local Remote = game.ReplicatedStorage.Network.Server.RemoteEvent
local Colors = {"Really red","White","Black"};
local Choosen = Colors[math.random(1,#Colors)]
local a = BrickColor.new(Choosen)
print(Choosen)

1 answer

✓ Accepted answer

You have to use the BrickColor.new constructor. And remember, you call functions with parenthasis ().

local Colors = {"Red","White","Black"};
local Choosen = Colors[math.random(1,#Colors)]
local a = BrickColor.new(Choosen)

10 comments

0

It always prints the color black

0

"Red" isn't a BrickColor. Try "Really red".

0

Even If I use numbers all of them equal one diget

0

If it's always choosing the same result, you should try setting a new random seed.

0

When I use random Seed such as "math.randomseed(tick()%1*1e6)" a error occurs

0

It shouldn't. There's probably some syntax error you're unaware of. Look for red underlines in your script, and analyze the error message telling you what's wrong.

0

Look at what I added to the desc. of question.

0

You didn't add the randomseed call to the revised version. Call it on the first line of your code in the revised version Goulstem provided.

0

Worked fine for me

0

It works now, I guess it was just where I had it placed in the script. Anyway, thank you so much for you help.

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