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

Color3 pick In order from variables on click?

I am trying to make a Script that changes the Color of the Part clicked In order of the Colors I give it but I can't figure out how to make It select different Variables In order.

My Code:

local variable = script.Parent:WaitForChild("ClickDetector")
wall = script.Parent.Color
colors = {255,0, 0}{0,255,0}{0,0,255}

variable.MouseClick:Connect(function()
	wall.BrickColor = BrickColor.Random(1, #colors) 
end)

1 answer

✓ Accepted answer

BrickColor.Random just returns a random BrickColor.

local colors = {
	{39, 70, 45},
	{255, 255, 127},
	{255, 85, 255}
	
}
local rng = Random.new() -- Random.new is the proper way to get a random number. We'll use this to select a random table number
local randomNum = rng:NextInteger(1,#colors) -- Choose random table item
local color = Color3.fromRGB(colors[randomNum][1],colors[randomNum][2],colors[randomNum][3]) -- Define the color for that table item
workspace.Baseplate.Color = color -- set part to color choosen

1 comment

0

Ohhh, I always used math.random Roblox has added so much since I used to be on here. Thank you so much for educating me!

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