local Roof = script.Parent.Parent.Glass:GetChildren() function ToggleCeiling() if script.Parent.Parent.State.Value == false then script.Parent.Parent.State.Value = true script.Parent.BrickColor = BrickColor.new("Bright red") Roof.BrickColor = BrickColor.new("Really white") Roof.Transparency = 0.7 Roof.Material = "Plastic" else script.Parent.Parent.State.Value = false script.Parent.BrickColor = BrickColor.new("Bright green") Roof.BrickColor = BrickColor.new("Really black") Roof.Transparency = 0 Roof.Material = "Wood" end end script.Parent.ClickDetector.MouseClick:connect(ToggleCeiling)
This only changes the color of the brick I am clicking. It won't change the other bricks.
So in the glass
, Are you sure that there are all parts
, becauseif there are not
allparts
, then it wont work.
ALSO, use if not, else, you have to put for the other part where you put else, "elseif then put the info next to it with two equal signs, then put a "then"
You could start by tidying it up a lot!
The problem is that Roof
is a table and you can't set the BrickColor
of a table!
You need to iterate through each element of the table (the individual Part
s) and set the BrickColor on them, so I've added in a function to do that (and to change the other properties).
local house = script.Parent.Parent --Call it whatever you want, though local Roof = house.Glass:GetChildren() function SetProperties(table, color, transparency, material) for _,v in pairs(table) do v.BrickColor = color v.Transparency = transparency v.Material = material end end function ToggleCeiling() state = house.State if not state.Value then state.Value = true script.Parent.BrickColor = BrickColor.new("Bright red") SetProperties(Roof, BrickColor.new("Really white"), 0.7, "Plastic") else state.Value = false script.Parent.BrickColor = BrickColor.new("Bright green") SetProperties(Roof, BrickColor.new("Really black"),0,"Wood") end end script.Parent.ClickDetector.MouseClick:connect(ToggleCeiling)
(There may be some slight syntactic mistakes, but you can figure those out!)
Hope that helps!