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

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

Asked by 5 years ago

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.

0
Just make a table of possible colors and use math.random() to pick out an index, from there just set it to that Vulkarin 581 — 5y
0
^ XX_Doggoa 24 — 5y

1 answer

Log in to vote
0
Answered by
Cyrakohl 108
5 years ago
Edited 5 years ago

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"

Ad

Answer this question