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

How would I get this script to change the colours of all the parts in a certain parent?

Asked by 5 years ago
Edited 5 years ago

This is my current script for a containment breach alarm.

Colour1 = "White"

Colour2 = "Really red"



On = false
Debounce = false
gc = script.Parent.Parent:GetChildren()
script.Parent.ClickDetector.MouseClick:Connect(function()
    if On == false and Debounce == false then
        Debounce = true
    game.Workspace.Sound.ContainmentAlarm:Play()
        On = true
            for i,v in pairs(gc) do
                if v.Name == "Change" then
                    v.BrickColor = BrickColor.new(Colour1)
                    wait(0)
                    v.BrickColor = BrickColor.new(Colour2)
                end
            end
            wait(3)
            Debounce = false

    elseif On == true and Debounce == false then
        On = false
        Debounce = true
            for i,v in pairs(gc) do
                if v.Name == "Change" then
                    v.BrickColor = BrickColor.new(Colour1)
                end
            end
            game.Workspace.Sound.ContainmentAlarm:Pause()
end
        wait(3)
        Debounce = false
end)

I want to change the colours of all the parts in 'game.Workspace["Light Switch"].Lights'

2 answers

Log in to vote
1
Answered by
oftenz 367 Moderation Voter
5 years ago
Edited 5 years ago

What you are trying to do is Instance.GetChildren.

local Colour1 = "White"
local Colour2 = "Really red"
local children =game.Workspace["Light Switch"].Lights:GetChildren() --Children of instance.
for i = 1, #children do
    children[i].BrickColor = BrickColor.new(Colour1)
end

This is a simple function of roblox. Let me know if there is an issue. Added into your script:

Colour1 = "White"

Colour2 = "Really red"



On = false
Debounce = false
gc = script.Parent.Parent:GetChildren()
local children =game.Workspace["Light Switch"].Lights:GetChildren() --Children of instance.
script.Parent.ClickDetector.MouseClick:Connect(function()
    if On == false and Debounce == false then
        Debounce = true
    game.Workspace.Sound.ContainmentAlarm:Play()
        On = true
            for i,v in pairs(gc) do
                if v.Name == "Change" then
            for i = 1, #children do
           children[i].BrickColor = BrickColor.new(Colour1)
            end
                    wait(0)
                    for i = 1, #children do
           children[i].BrickColor = BrickColor.new(Colour2)
           end
                end
            end
            wait(3)
            Debounce = false

    elseif On == true and Debounce == false then
        On = false
        Debounce = true
            for i,v in pairs(gc) do
                if v.Name == "Change" then
            for i = 1, #children do
           children[i].BrickColor = BrickColor.new(Colour1)
            end
                end
            end
            game.Workspace.Sound.ContainmentAlarm:Pause()
end
        wait(3)
        Debounce = false
end)

I'm confuzed why you wait(0) but I integrated it into your script.

0
Thank you tictac67 96 — 5y
0
Can you add it into my script? tictac67 96 — 5y
0
Right now the lights wont turn off red when I turn the alarm on tictac67 96 — 5y
0
Yeah hold on oftenz 367 — 5y
0
updated oftenz 367 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

EDIT

I managed to do it with this:

Colour1 = "Gray"
Colour2 = "Really red"


local children = game.Workspace["Light Switch"].Lights:GetChildren() --Children of instance.
On = false
Debounce = false
gc = game.Workspace["Light Switch"].Lights:GetChildren()
script.Parent.ClickDetector.MouseClick:Connect(function()
    if On == false and Debounce == false then
        Debounce = true
    game.Workspace.Sound.ContainmentAlarm:Play()
    script.Parent.Parent.BreachLight.BrickColor=BrickColor.new("Really red")
        On = true
            for i,v in pairs(gc) do
                if v.Name == "Light" then
                    v.BrickColor = BrickColor.new(Colour1)
                    wait(0)
                    v.BrickColor = BrickColor.new(Colour2)
                end
            end
            wait(3)
            Debounce = false

    elseif On == true and Debounce == false then
        On = false
        Debounce = true
            for i,v in pairs(gc) do
                if v.Name == "Light" then
                    v.BrickColor = BrickColor.new(Colour1)
                end
            end
            game.Workspace.Sound.ContainmentAlarm:Pause()
            script.Parent.Parent.BreachLight.BrickColor=BrickColor.new("Institutional white")
end
        wait(3)
        Debounce = false
end)

Answer this question