Hello, how do i make all lights to turn off?
i tried to make one but it doesnt work
local light = game.Workspace.BackroomsStuff.LightCeiling.Light
light.BrickColor = BrickColor.new(0, 0, 0)
light.SurfaceLight.Brightness = 0
Hello, how do i make all lights to turn off?
i tried to make one but it doesnt work
local light = game.Workspace.BackroomsStuff.LightCeiling.Light
light.BrickColor = BrickColor.new(0, 0, 0)
light.SurfaceLight.Brightness = 0
local lights = game.Workspace.BackroomsStuff:GetChildren()
for i=1, #lights do
lights[i].Light.SurfaceLight.Brightness = 0
end
Insert this script into your Backroomstuff folder, no need to insert it into each light
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
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
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.