Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can someone help me by fixing this script?

Asked by 10 years ago
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

Log in to vote
-1
Answered by
Hybric 271 Moderation Voter
10 years ago

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"

0
Yes. They are all parts. yoshi1195 0 — 10y
0
Can you change the script for me? I just don't get it. yoshi1195 0 — 10y
0
Just PM me it Hybric 271 — 10y
Ad
Log in to vote
-1
Answered by
duckwit 1404 Moderation Voter
10 years ago

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!

0
It works. Thanks! yoshi1195 0 — 10y
0
Awesome! Please remember to mark an answer as the correct one when you're done with the thread, that's how SH works! :) duckwit 1404 — 10y

Answer this question