How to make random colored parts but with the selection of only 4 colors?

Using the Random() method doesnt work cus it uses all possible colors from the value 255,255,255 - 0,0,0

while true do
local p = workspace.light.p
p.BrickColor = BrickColor.Random()
end

So I wanted it to be randomised but with only green,blue,red and yellow
Any help?

5 Likes

Please specify the type so of red, green, blue and yellow. There’s like dark yellow, light red like that.

1 Like

245, 205, 48 = Bright Yellow
9, 137, 207 = Electric Blue
196, 40, 28 = Bright Red
0,255,0 = Lime green

1 Like

So you want it to randomise between just red, green, blue and yellow? You can just make an array with those colors and then loop through it, right? Or is that not the case.

2 Likes

If you want to get some random specific colors you can create a table of all the colors and choose a random one.

1 Like

How do you do that? Dont mind this

Just do

local colors = { -- all of the potential colors
Color3.fromRGB(245, 205, 48);
Color3.fromRGB(9, 137, 207);
Color3.fromRGB(196, 40, 28);
Color3.fromRGB(0,255,0);
}

local color = colors[math.random(1, #colors)] --the chosen color
1 Like

Try this.

local colours = {
    “(The RGB value of each color you want.)”;
    “(Continue if you want more.)”
}

local finalColourChoice

for i,v in pairs(colours) do
    v = tonumber(v)
    finalColourChoice = v
end

Now you can take finalColourChoice and apply that RGB value to the material. I hope this works.

1 Like

DAMN it, I should’ve use number, not strings. I think your code can work.

1 Like
local colors = { -- all of the potential colors
Color3.new(245, 205, 48);
Color3.new(9, 137, 207);
Color3.new(196, 40, 28);
Color3.new(0,255,0);
}

local color = colors[math.random(1, #colors)]
--My attempt
while true do
p.BrickColor = BrickColor.new(color,color,color)
wait(1)
end

Somehow it turns white

My bad my bad my bad I always accidently do Color3.new when its supposed to be Color3.fromRGB

also do p.Color = color and put the color variable inside of the loop to get random color every time

1 Like

Alright then this is my “fix”

local colors = {
		Color3.fromRGB(245, 205, 48);
		Color3.fromRGB(0, 137, 207);
		Color3.fromRGB(196, 40, 28);
		Color3.fromRGB(0,255,0);
	}
	
local color = colors[math.random(1, #colors)]
while true do
	script.Parent.Color = color
	wait(1)
end

Hey, should it be BrickCOlor or Color? Sorry I didnt read your edit right after I replied hehe :sweat_smile:

1 Like

brick color refers to like just the string of the actual color while Color refers to a specific color input

--example
game.Workspace.Baseplate.BrickColor = BrickColor.Red()
2 Likes

As its a Color3 Value thats going to be selected, you need to assign it to the Color property.

1 Like

Output didnt return an error but the brick didnt change its color

If its staying at one consistent color then like I said before you have to put the variable inside of the while loop for it to change colors

1 Like

But this is the variable “color” inside the loop

while true do
    local color = colors[math.random(1, #colors)]
	script.Parent.Color = color
wait(1)
end
3 Likes

Oh right, understood but Hey! It works now, thank you very much :smiley: