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

how do you make a proper color randomizer?

i'm not very good at this but i can't find anything talking about this so...

local part = game.StarterPlayer.StarterCharacter.field local colour = math.random(1, 6)

if colour == 1 then part.BrickColor.new("Light blue") end

if colour == 2 then part.BrickColor.new("Lime green") end

if colour == 3 then part.BrickColor.new("New yeller") end

if colour == 4 then part.BrickColor.new("Deep orange") end

if colour == 5 then part.BrickColor.new("Really red") end

if colour == 6 then part.BrickColor.new("Royal purple") end

please tell me what i'm doing wrong

1 comment

0

You set a part's Brick color by doing PART.BrickColor = BrickColor.new("Your Color")

3 answers

You can just use BrickColor.random()

local part = game.StarterPlayer.StarterCharacter.field --Your part
part.BrickColor = BrickColor.random() --Generate a random color

BrickColor

You could shorten your script by using a Table

In a Table, you write the BrickColor's that you want to be randomized, if you want them to be specified, and not all the colors. If you want from all the random colors in the game, just do BrickColor.Random()

workspace.Part.ClickDetector.MouseClick:Connect(function()
	local theRandomColors = {BrickColor.Black(), BrickColor.Green(), BrickColor.Red()}
	
	
	workspace.Baseplate.BrickColor = theRandomColors[math.random(1, #theRandomColors)]
end)

both of your answers are correct but if you want an ABSOLUTE random color, then use math .random for RGB. Using BrickColor.random() is only for random brick colors, but there are actually a lot more colors in the game. BrickColors are only from the pallette, so Instead of BrickColor with only limitted options, use the RGB method (red, green, blue) by using .Color and change it by using Color3.

So to get random numbers for the RGB values to get the most randomized colors you can get, simply use this:

Part.Color = Color3.fromRGB(math.random(0,255),math.random(0,255),math.random(0,255))

this will make all 3 color values randomized from 0(the lowest possible which is no color meaning it doesnt show that color) and 255(the highest possible amount which is show the most of that color)

Edit: Sorry i made it Color3.new i forgot thats for 0-1, color3.fromRGB is same thing but with the normal computer color scale which is 0-255

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