Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 7 years ago
Edited 7 years ago

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

Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
7 years ago

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)
0
It always prints the color black SilentGalaxZy 53 — 7y
0
"Red" isn't a BrickColor. Try "Really red". Goulstem 8144 — 7y
0
Even If I use numbers all of them equal one diget SilentGalaxZy 53 — 7y
0
If it's always choosing the same result, you should try setting a new random seed. ScriptGuider 5640 — 7y
View all comments (6 more)
0
When I use random Seed such as "math.randomseed(tick()%1*1e6)" a error occurs SilentGalaxZy 53 — 7y
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. ScriptGuider 5640 — 7y
0
Look at what I added to the desc. of question. SilentGalaxZy 53 — 7y
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. ScriptGuider 5640 — 7y
0
Worked fine for me Goulstem 8144 — 7y
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. SilentGalaxZy 53 — 7y
Ad

Answer this question