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'
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.
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)