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

Random brick color once the game starts?

I want a brick to be a random color from a certain list of colors and to never change again. Sort of like

while true do
script.Parent.BrickColor = BrickColor.Random() 
wait(0.5)
end

Except it's just 3 different colors it changes to and it never changes colors again.

2 answers

You do not need a loop as script automatically run the second you run the game

script.Parent.BrickColor = BrickColor.Random()

That is all you need

instead of doing

while true do
script.Parent.BrickColor = BrickColor.Random() 
wait(0.5)
end

You can simply do this and it will do pretty much the same thing

While wait(0.5) do
	script
end

Sorry If I wasn't much help but this is what I think you wanted to know.

1 comment

0

Put this as a serverscript Hope it helps u out

Remove the while true, and make a table/array of the colors you want. Then use this code:

colors = {"Really red", "Really blue", "Really black"}

random = math.random(1, #colors)

script.Parent.BrickColor = BrickColor.new(colors[random])

What it does is it creates a table/array of color names, and after that picks a random number between 1, and the number of values in that array. Then, if you use that random number as the array index for the colors table:

script.Parent.BrickColor = BrickColor.new(colors[random])

colors[random] -- This is the important thing

then it essentially picks a random color. You might want to use randomseed as well to make sure you have totally random numbers:

math.randomseed(tick())

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