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

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

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

✓ Accepted answer

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.

5 comments

0

Thank you

0

Can you add it into my script?

0

Right now the lights wont turn off red when I turn the alarm on

0

Yeah hold on

0

updated

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)

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