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

How do you make a color changing script to three specific colors?

Ok, so I have a script and I know it says that when you click it makes a random color as shown below,

script.Parent.ClickDetector.MouseClick:Connect(function()
	script.Parent.BrickColor = BrickColor.Random()
end)

but I have tried to findle around with it and try to make it to a three specific colors which are, Carnation pink, Mint, and Pine cone. I also want to try to fit it into one whole script, but that makes it more complex for me to work with settings as a new scripter.

2 comments

0

Just make a table of possible colors and use math.random() to pick out an index, from there just set it to that

0

^

1 answer

✓ Accepted answer

Hey there for starters we are going to create a table of the specific colours that we need:

local Colors = {BrickColor.new("Bright red"),BrickColor.new("Black"),BrickColor.new("Pink")}

So we have our table set now we just need to make it so when the player clicks on our part it will change colour!

script.Parent.ClickDetector.MouseClick:Connect(function()
	
	local RandomisedResult = Colors[math.random(1,#Colors)]
	script.Parent.BrickColor = RandomisedResult
end)

So I assume you know how connecting an event to a function works so i'll leave that as something you already know!.

So abit of context of how this code works the variable RandomisedResult uses the math.random() function and goes from 1 to the end value of the table in this case "Pink"

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