Hi, i am trying to make a system where windows turn on like if light turned on, And it works really really well, Execpt it sucks, Yup, It does it really well but it just keeps going and going like one light turns on then the other then the other then the other ect, intill ALL of them turn on (which clearly is not the thing i want) heres the script:
local Lighting = game.Lighting
local CS = game:GetService("CollectionService")
local function WindowLight(Window)
local Va = 1
local Su = Window.SurfaceGui
local Su2 = Window.SurfaceGui2
local Image = Su.ImageLabel
local Image2 = Su2.ImageLabel
Va = math.random(1, 5)
if Va == 4 then
Su.LightInfluence = 0
Image.BackgroundColor3 = Color3.new(1, 1, 0.709804)
elseif Va == 2 then
Su2.LightInfluence = 0
Image2.BackgroundColor3 = Color3.new(1, 1, 0.709804)
end
end
local function WindowTurnOffLight(Window)
local Su = Window.SurfaceGui
local Su2 = Window.SurfaceGui2
local Image = Su.ImageLabel
local Image2 = Su2.ImageLabel
Su.LightInfluence = 1
Su2.LightInfluence = 1
Image.BackgroundColor3 = Color3.new(0.996078, 1, 0.941176)
Image2.BackgroundColor3 = Color3.new(0.996078, 1, 0.941176)
end
Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
if Lighting.ClockTime>= 18.5 or Lighting.ClockTime <= 7 then
for i, v in pairs(CS:GetTagged("WindowLight")) do
WindowLight(v)
wait(0.5)
end
elseif Lighting.ClockTime >= 7 or Lighting.ClockTime <= 18.5 then
for i, v in pairs(CS:GetTagged("WindowLight")) do
WindowTurnOffLight(v)
end
end
end)
I am sure it is the wait(0.5) below WindowLight(v) what is causing the delay between each window light (because it yields the script for 0.5 seconds after each light gets turned on), try making the putting:
wait() – this should make them light up all at once! EDIT: By this i mean just remove the 0.5 in the brackets on wait() to remove the delay between each window turning on
The below should make it run a certain amount of times although a flaw is that it can try to turn the same window on multiple times
local WindowTable = CS:GetTagged("WindowLight")
local AmountToLight = math.random(1,#WindowTable)
for i=1, AmountToLight do
task.wait(0.5)
local Window = WindowTable[1,#WindowTable]
WindowLight(Window)
end
Also minor suggestion, there’s a logic error at these lines of code. To fix this, replace the or’s with and’s like this, so that the lights will turn on/off at the correct times:
if Lighting.ClockTime>= 18.5 and Lighting.ClockTime <= 7 then
elseif Lighting.ClockTime >= 7 and Lighting.ClockTime <= 18.5 then