How to make the lights randomized?

So I had an idea to make a building for like a background and it has many lights. The script that I am trying to know is how do you make the lights of this building randomized. Like if the in game time reaches 17.5 / 17:30:00 some or all lights on the windows will turn on/ from the HTML: #000000 (Off/ just the darkest black) to HTML: #b4b276 (kinda a yellowish color) , and if it reaches 7 as the in game time it will turn all lights off/ HTML: #b4b276 to HTML: #000000.

The issue is that the lights don’t turn on at 17.5/ 17:30:00 Clock time in game, and I am uncertain that is the table in the script I made the problem or is it the Lighting
= game:GetService(“Lighting”) and Lighting.Clocktime the problem.

So here is the video of it on this Youtube link

The solutions I tried so far was changing the table on the local Light_Randomizer = Random (Light Table) into the actual table itself not the shortcut version “local Light_Table”, and if the Lighting.Clocktime is the problem, then how do you fix it?/ or what could be an alternative to it?

So the script that I used and made is this:

local Lights = script.Parent

local Lighting  = game:GetService("Lighting")

local Light_Table = {Lights.Window_Inner_1, Lights.Window_Inner_2, 
	Lights.Window_Inner_3, Lights.Window_Inner_4, Lights.Window_Inner_5,
	Lights.Window_Inner_6, Lights.Window_Inner_7, Lights.Window_Inner_8,
	Lights.Window_Inner_9, Lights.Window_Inner_10, Lights.Window_Inner_11,
	Lights.Window_Inner_12, Lights.Window_Inner_13, Lights.Window_Inner_14,
	Lights.Window_Inner_15, Lights.Window_Inner_16, Lights.Window_Inner_17,
	Lights.Window_Inner_18, Lights.Window_Inner_19, Lights.Window_Inner_20}

while true do
	wait()
	if Lighting.ClockTime == 17.5 then
		
		local Light_Randomizer = Random (Light_Table)

		local On_Off_Randomizer = Random (1,2)

		if On_Off_Randomizer == 1 then
			Light_Randomizer.Color  = Color3.fromRGB(0, 0, 0)
		end

		if On_Off_Randomizer == 2 then
			Light_Randomizer.Color = Color3.fromRGB(180, 178, 118)

			wait()
			if Lighting.ClockTime == 7 then
				Light_Table.Color  = Color3.fromRGB(0, 0, 0)
			end
		end
	end
end

Clock time,i think is a write only mean you cannot make it trigger a thing,Use GetMinutesAfterMidnight instead.

1 Like

Seems like I figured it out myself but I would like to thanks to the person who tried to help me ( @tin_nim ) to fix the script.

local Lights = script.Parent

local Lighting  = game:GetService("Lighting")

local Light_Table = {Lights.Window_Inner_1, Lights.Window_Inner_2, 
	Lights.Window_Inner_3, Lights.Window_Inner_4, Lights.Window_Inner_5,
	Lights.Window_Inner_6, Lights.Window_Inner_7, Lights.Window_Inner_8,
	Lights.Window_Inner_9, Lights.Window_Inner_10, Lights.Window_Inner_11,
	Lights.Window_Inner_12, Lights.Window_Inner_13, Lights.Window_Inner_14,
	Lights.Window_Inner_15, Lights.Window_Inner_16, Lights.Window_Inner_17,
	Lights.Window_Inner_18, Lights.Window_Inner_19, Lights.Window_Inner_20}


while true do
	wait(.01)
	if Lighting.ClockTime > 17.5 then
		
		Light_Randomizer = (Light_Table[math.random(1,#Light_Table)])

		On_Off_Randomizer = math.random(1,3)

		if On_Off_Randomizer == 1 then
			Light_Randomizer.Color  = Color3.fromRGB(0, 0, 0)
			
			end

		if On_Off_Randomizer == 2 then
			Light_Randomizer.Color = Color3.fromRGB(180, 178, 118)
			
			end
		
		if On_Off_Randomizer == 3 then
			Light_Randomizer.Color = Color3.fromRGB(180, 178, 118)
			
			end
		
		wait(.99)
		
		end
	
	if Lighting.ClockTime == 0 then
		
		Light_Randomizer = (Light_Table[math.random(1,#Light_Table)])

		On_Off_Randomizer = math.random(1,3)

		if On_Off_Randomizer == 1 then
			Light_Randomizer.Color  = Color3.fromRGB(0, 0, 0)

		end

		if On_Off_Randomizer == 2 then
			Light_Randomizer.Color = Color3.fromRGB(180, 178, 118)

		end

		if On_Off_Randomizer == 3 then
			Light_Randomizer.Color = Color3.fromRGB(180, 178, 118)
		end
		
		wait(.99)
		
	end
	
	if Lighting.ClockTime == 7 then
		Lights.Window_Inner_1.Color = Color3.fromRGB(0, 0, 0)
		Lights.Window_Inner_2.Color = Color3.fromRGB(0, 0, 0)
		Lights.Window_Inner_3.Color = Color3.fromRGB(0, 0, 0)
		Lights.Window_Inner_4.Color = Color3.fromRGB(0, 0, 0)
		Lights.Window_Inner_5.Color = Color3.fromRGB(0, 0, 0)
		Lights.Window_Inner_6.Color = Color3.fromRGB(0, 0, 0)
		Lights.Window_Inner_7.Color = Color3.fromRGB(0, 0, 0)
		Lights.Window_Inner_8.Color = Color3.fromRGB(0, 0, 0)
		Lights.Window_Inner_9.Color = Color3.fromRGB(0, 0, 0)
		Lights.Window_Inner_10.Color = Color3.fromRGB(0, 0, 0)
		Lights.Window_Inner_11.Color = Color3.fromRGB(0, 0, 0)
		Lights.Window_Inner_12.Color = Color3.fromRGB(0, 0, 0)
		Lights.Window_Inner_13.Color = Color3.fromRGB(0, 0, 0)
		Lights.Window_Inner_14.Color = Color3.fromRGB(0, 0, 0)
		Lights.Window_Inner_15.Color = Color3.fromRGB(0, 0, 0)
		Lights.Window_Inner_16.Color = Color3.fromRGB(0, 0, 0)
		Lights.Window_Inner_17.Color = Color3.fromRGB(0, 0, 0)
		Lights.Window_Inner_18.Color = Color3.fromRGB(0, 0, 0)
		Lights.Window_Inner_19.Color = Color3.fromRGB(0, 0, 0)
		Lights.Window_Inner_20.Color = Color3.fromRGB(0, 0, 0)
	end
end

edit from 5-19-2021

So the building now looks like this

from Floor_1 (the floor named 1st floor but is actually on the 2nd floor) it was duplicated until it reached Floor_12. The script is all the same since it was all duplicated from the 1st floor.

1 Like