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

change properties of all bricks in one parent?

Asked by 6 years ago

Right now I have this for my generator:

-- FOG = 150
-- AmbiantOutside = 62,62,62
DeBounce = false
Model = script.Parent.Parent

local lights = {}
local function FindLights(obj)
    for _, child in pairs(obj:GetChildren()) do
        if child:IsA("Light") then
            table.insert(lights, child)
        end
        FindLights(child)
    end
end
FindLights(game.Workspace["Light Switch A"].Lights)

function OnClick(Player)
    if script.Value.Value == 1 then
            if DeBounce == false then
                DeBounce = true
                Model.Status.Sound:Play()
                wait(1.3)
                Model.Screen.BrickColor = BrickColor.new("Really black")
                Model.Status.BrickColor = BrickColor.new("Really red")
                for _, light in pairs(lights) do
                    light.Range = light.Range - 15
                    workspace.LightsB.SurfaceLight.Range = light.Range - 15
                    workspace.LightsB.ReLight.Enabled=true
                    workspace.LightsC.SurfaceLight.Range = light.Range - 15
                    workspace.LightsC.ReLight.Enabled=true
                    workspace["Light Switch A"].Lights.Material="Plastic"
                    workspace["Light Switch A"].Lights.BrickColor=BrickColor.DarkGray()
                    workspace["Light Switch A"].Lights.ReLight.Enabled=true
                    workspace.Floorlight.Material="Plastic"
                    workspace.Floorlight1.Material="Neon"
                    workspace.Floorlight2.Material="Neon"
                    workspace.Floorlight3.Material="Neon"
                    workspace.Floorlight4.Material="Neon"
                    workspace.Floorlight.BrickColor=BrickColor.DarkGray()
                    workspace.Floorlight1.BrickColor=BrickColor.Red()
                    workspace.Floorlight2.BrickColor=BrickColor.Red()
                    workspace.Floorlight3.BrickColor=BrickColor.Red()
                    workspace.Floorlight4.BrickColor=BrickColor.Red()
                    workspace.FloorlightB.BrickColor=BrickColor.DarkGray()
                    workspace.FloorlightB.Material="Plastic"
                    workspace.LightsB.Material="Plastic"
                    workspace.LightsB.BrickColor=BrickColor.DarkGray()
                    workspace.LightsC.Material="Plastic"
                    workspace.LightsC.BrickColor=BrickColor.DarkGray()
                    workspace.FloorlightC.BrickColor=BrickColor.DarkGray()
                    workspace.FloorlightC.Material="Plastic"
                end
                game.Lighting.FogEnd = game.Lighting.FogEnd - 50
                game.Workspace.Sound.PowerDown:Play()
                Model.Exhaust.Smoke.Enabled = false
                wait(1)
                repeat Model.Body.Sound.Volume = Model.Body.Sound.Volume - .1
                    wait(.1)
                until Model.Body.Sound.Volume <= 0
                wait(1)
                script.Value.Value = 2
                DeBounce = false
                end
elseif script.Value.Value == 2 then
            if DeBounce == false then
                DeBounce = true
                Model.Status.Sound:Play()
                wait(1.3)
                Model.Screen.BrickColor = BrickColor.new("White")
                Model.Status.BrickColor = BrickColor.new("Lime green")
                for _, light in pairs(lights) do
                    light.Range = light.Range + 15
                    workspace["Light Switch A"].Lights.Material = "Neon"
                    workspace["Light Switch A"].Lights.BrickColor=BrickColor.Gray()
                    workspace["Light Switch A"].Lights.ReLight.Enabled=false
                    workspace.Floorlight.Material="Neon"
                    workspace.FloorlightB.Material="Neon"
                    workspace.Floorlight1.Material="Plastic"
                    workspace.Floorlight2.Material="Plastic"
                    workspace.Floorlight3.Material="Plastic"
                    workspace.Floorlight4.Material="Plastic"
                    workspace.Floorlight.BrickColor=BrickColor.Gray() 
                    workspace.Floorlight1.BrickColor=BrickColor.DarkGray()
                    workspace.Floorlight2.BrickColor=BrickColor.DarkGray()
                    workspace.Floorlight3.BrickColor=BrickColor.DarkGray()
                    workspace.Floorlight4.BrickColor=BrickColor.DarkGray()
                    workspace.FloorlightB.BrickColor=BrickColor.Gray()
                    workspace.LightsB.SurfaceLight.Range = light.Range + 15
                    workspace.LightsB.ReLight.Enabled=false
                    workspace.LightsB.BrickColor=BrickColor.Gray()
                    workspace.LightsB.Material="Neon"
                    workspace.FloorlightB.BrickColor=BrickColor.Gray()
                    workspace.LightsC.SurfaceLight.Range = light.Range + 15
                    workspace.LightsC.ReLight.Enabled=false
                    workspace.LightsC.BrickColor=BrickColor.Gray()
                    workspace.LightsC.Material="Neon"
                    workspace.FloorlightB.BrickColor=BrickColor.Gray()
                    workspace.FloorlightC.BrickColor=BrickColor.Gray()
                    workspace.FloorlightC.Material="Neon"
                end
                game.Lighting.FogEnd = game.Lighting.FogEnd + 50
                game.Workspace.Sound.PowerUp:Play()
                Model.Exhaust.Smoke.Enabled = true
                repeat Model.Body.Sound.Volume = Model.Body.Sound.Volume + .1
                wait(.1)
                until Model.Body.Sound.Volume >= 1
                wait(1)
                script.Value.Value = 1
                DeBounce = false
            end
        end
    end

script.Parent.ClickDetector.MouseClick:connect(OnClick)

But instead of writing a separate line for each light I want to just put something that will change all the bricks within a certain part/folder.

0
for i,v in pairs(object:GetChildren()) do if v:IsA('BasePart') then v.Transparency = 1 end end --> Like this? User#20388 0 — 6y
0
Can you answer with a code block? I am not very good at editing tictac67 96 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

First you would need to group the part(s) that you want to change the properties for. make sure that the group name isnt the same somewhere else in workspace. im not going to write out the whole script, but to get the parts in a group (not sure if it works the same with a folder) you would do

for _,v in pairs(game.Workspace.PutTheGroupNameHere:GetChildren()) do
    --Anything in here is what your changing for everything inside that group
end
0
Would this be able to change the material of the parts? tictac67 96 — 6y
0
yes, all the parts in that model would be changed to the selected material you chose. cruizer_snowman 117 — 6y
Ad

Answer this question