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

Random brick color once the game starts?

Asked by 6 years ago

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

Log in to vote
0
Answered by 6 years ago

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.

0
Put this as a serverscript Hope it helps u out Sergiomontani10 236 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

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())

Answer this question