Color Changing Bricks

Hey, everyone!
I’ve been trying to get a brick to change color when clicked, and then change back to the original color when clicked again.
I’ve figured out how to do the first part (YouTube Video), but I don’t know, and can’t find, the other half.
Current Script:

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

Thanks!

3 Likes

You could save the part’s original color at the start of this script and use a debounce to know which mode it is set in, like so:

local color = script.Parent.BrickColor
local debounce = false

script.Parent.ClickDetector.MouseClick:Connect (function()
    if not debounce then
        script.Parent.BrickColor= BrickColor.Red()
        debounce = true
    else
        script.Parent.BrickColor = color
        debounce = false
    end
end)
1 Like
script.Parent.ClickDetector.MouseClick:Connect (function()
     if script.Parent.BrickColor = BrickColor.Blue() then
          script.Parent.BrickColor= BrickColor.Red()
     else
          script.Parent.BrickColor= BrickColor.Blue()
     end
end)

If statements, my friend.

1 Like

Thanks so much! This really helps!