Part that changes color when you click on it but stops when it lands on a certain color issue

Hello, I have managed to make the part change colors when you click it but am not able to make it so when you click it a random time, if you get the color you need the ClickDetector will be destroyed.

1 Like

Could you provide the script you’re attempting to use to achieve this? We would be able to diagnose your problem better and give you reasoning on why!

1 Like

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

script.Parent.BrickColor = BrickColor.Random()
if BrickColor.new(“Forest green”) then
script.Parent.ClickDetector:Destroy
end)

I have this but can’ make it get destroyed

1 Like

Ah, alright. An example of destroying a part when it’s a certain color would be:

if script.Parent.BrickColor.Name == "Forest green" then
	script.Parent.ClickDetector:Destroy()
end

2 Likes

There are a lot of BrickColor values, it’s possible the one you’re attempting to match won’t be randomly selected.

True…true… then how would I make it be a selected few that would be random.

1 Like

A simple way would be to check if the BrickColor’s name contains a particular color.

if part.BrickColor.Name:lower():match("red") then
	part:Destroy()
end