Chaning a parts colour

Trying to change a parts color when another part is clicked. The answer is most likely very clear but I’m very new to scripting and need help.

Here I have a part with a script and a click detector:

Screenshot (539)

In that script is this code:

local energy = game.Workspace.Energy1

function onClicked()
	energy.BrickColor = BrickColor.new(255,255,255)
end 

script.Parent.ClickDetector.MouseClick:connect(onClicked)

Thanks.

2 Likes

Good day! Here’s some code that might help you!

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

If you’d like anything else, please shoot a reply!

1 Like
local energy = game.Workspace.Energy1

function onClicked()
	energy.BrickColor = BrickColor.new("Institutional White")
end 

script.Parent.ClickDetector.MouseClick:Connect(onClicked)

BrickColors can only handle string colors! Hopefully this helps! :smile:

1 Like

Oh thanks! Is there anyway that I could make it a specific colour?

Yep! Refer to this document for the names of the colors!
(Also, if you could mark anyone as solution to help with the SEO, that would be amazing!) :slight_smile:

1 Like