When creating my windows, I needed to give them light as not all buildings leave their lights off when night falls and its still occupied. To this, I made a script that when the time reaches 17.8 (17:48 or 5:48 PM), the window lights should turn on. Of course, I can’t have every light on, so I wanted to make a randomizer where a window has a 1/128 chance of being turned on. However, when I do this, with the “wait(1)” at the end, the windows would end up flickering, so I needed to fix that, and to do so, I modified the script to look like this:
local light = script.Parent
local lightingpart = script.Parent.Parent
while true do
times = game.Lighting.ClockTime
loadshedding = math.random(1, 128)
print("Loadshedding stage", loadshedding)
if times >= 17.8 or times <= 6.3 and loadshedding > 65 then
light.Enabled = true
lightingpart.Material = "Neon"
lightingpart.Color = Color3.fromRGB(171, 144, 85)
else
light.Enabled = false
lightingpart.Material = "Glass"
lightingpart.Color = Color3.fromRGB(4, 21, 53)
end
wait(15)
end
These were my results:
I’ve checked the console, too, as it should print a number and if the number is below 65, the window lights should be on
Regardless of the number, the window lights always stay on.
I’ve tried changing the “>” to a “<” and adding equal signs to them, and I’ve done several modifications that I haven’t recorded, but they turn up with either the same result where all the lights are on, or just breaks it
All I’m trying to do is make Windows that, every 9:00 AM (9:00), the script would choose a random number for each window to determine whether a window will be on from 17:48 to 6:18, and after that, a new number would be chosen