Off Button for Light Generator

  1. What do you want to achieve? I want to make an off button that deletes the children of a specific part and change the material and color.

  2. What is the issue? The code only works up to the :ClearAllChildren() part.

  3. What solutions have you tried so far? Since the material of the part was neon and I wanted it to turn black, I tried to change the part’s material to metal. Also tried putting that part of code above the :ClearAllChildren() part of the script.
    I put so many .Parent because the script was in a click detector, in a part, in a folder and after that is a model.

script.Parent.MouseClick:Connect(function()
	local light = script.Parent.Parent.Parent.Parent:WaitForChild("Light")
	light:ClearAllChildren()
	light.BrickColor = "Black"
end)

Sorry if I wasted your time I’m still learning how to script :frowning:

Hey! Try this:

script.Parent.MouseClick:Connect(function()
local light = script.Parent.Parent.Parent.Parent:WaitForChild(“Light”)
light:ClearAllChildren()
light.BrickColor = BrickColor.new(“Black”)
end)

.

The reason it isn’t working is this line.

It needs to be light.BrickColor = BrickColor.new(“Black”)

Oh ok I didn’t realize that! Thx for the help! :smiley:

Your welcome. It still confuses me why it works like that.

You could also have used Color3.
It is similar to brickcolor, except you use RGB values to get custom colors.

Both work fine, and in your case brickcolor would work the same as color3

You can read about it here