How do i make ALL lights to turn off?

Hello, how do i make all lights to turn off?
Снимок экрана 2022-03-26 182811
i tried to make one but it doesnt work :frowning:

local light = game.Workspace.BackroomsStuff.LightCeiling.Light
light.BrickColor = BrickColor.new(0, 0, 0)
light.SurfaceLight.Brightness = 0
2 Likes
local lights = game.Workspace.BackroomsStuff:GetChildren()
for i=1, #lights do
    lights[i].Light.SurfaceLight.Brightness = 0
end
1 Like

Insert this script into your Backroomstuff folder, no need to insert it into each light

1 Like

Light is not a valid member of Part “Workspace.BackroomsStuff.Floor”

It means you have a part named floor in your folder, keep in it only lights, or do this instead

local lights = game.Workspace.BackroomsStuff:GetChildren()
for i=1, #lights do
    if lights[i].Name == "LightCeiling" do
    lights[i].Light.SurfaceLight.Brightness = 0
    end
end

This script will work for every light in the game.

local function turnOnLight(Folder)
   for _, light in pairs(:GetDescendants()) do
      if light:IsA("Light") then
         Light.Brightness = Light:GetAttribute("OldBrightness") or 10

         local oldColor = Light.Parent:IsA("BasePart") and Light.Parent:GetAttribute("OldColor")
         if oldColor then -- change the part color
            Light.Parent.Color = oldColor
         end
      end
   end
end

local function turnOffLight(Folder)
   for _, light in pairs(:GetDescendants()) do
      if light:IsA("Light") then
         Light:SetAttribute("OldBrightness", Light.Brightness)
         Light.Brightness = 0

         if Light.Parent:IsA("BasePart") then -- change the part color
            Light.Parent.Color = Color3.new(0, 0, 0)
            Light.Parent:SetAttribute("OldColor", Light.Parent.Color)
         end
      end
   end
end

local function flickerLight()
   turnOffLight(workspace:WaitForChild("BackroomsStuff"))
   wait(.1)
   turnOnLight(workspace:WaitForChild("BackroomsStuff"))
end

while true do
   wait(math.random(5,20))
   flickerLight()
   wait(math.random(1,5)/2)
   flickerLight()
   wait(math.ranomd(2,5))
   flickerLight
end
1 Like

You could just do a for loop (for i, v in pairs() do ) and then just have the thing it go through as the children of the BackroomStuff.

(then you just do like v.Light.SurfaceLight and then whatever u wanna do to turn it on)

@Invential smthing like this should work I think.

for i, v in pairs(game.Workspace.BackroomStuff:GetChildren()) do

v.Light.SurfaceLight.Brightness = 0

v.light.BrickColor = BrickColor.new(0, 0, 0)

end
1 Like

i tried this one, only light models in a folder, still, gives me an error. SurfaceLight is not a valid member of Part “Workspace.BackroomsStuff.LightCeiling.Light”

local backroomsFolder = workspace.BackroomsStuff

local function toggleLights(bool)
	for _, lightModel in ipairs(backroomsFolder:GetChildren()) do
		if lightModel:IsA"Model" then
			if lightModel.Name == "LightCeiling" then
				local lightPart = lightModel:FindFirstChild"Light"
				if lightPart then
					local surfaceLight = lightPart:FindFirstChildOfClass"SurfaceLight"
					if surfaceLight then
						surfaceLight.Enabled = bool
					end
				end
			end
		end
	end
end

Just call the function and pass true or false to it in order to toggle the lights.