Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Can someone help me by fixing this script?

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.

2 answers

So in the glass, Are you sure that there are all parts, because if there are not all parts, 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"

3 comments

0

Yes. They are all parts.

0

Can you change the script for me? I just don't get it.

0

Just PM me it

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 Parts) 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!

2 comments

0

It works. Thanks!

0

Awesome! Please remember to mark an answer as the correct one when you're done with the thread, that's how SH works! :)

This discussion is preserved as it was. New answers, comments, and votes are closed.