Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to create timed lighting?

Hi

I'm trying to create a light that follows the game lighting. So the lights will switch on at a certain time and switch off at a certain time as well.

I tried it out but failed. Can someone help me out?

-- Variables -
light = script.Parent.SurfaceLight

-- Main --
wait()
while true do
	if ("18:00:00" <= game.Lighting.TimeOfDay <= "06:00:00") then
		light.Enabled = false
	else
		light.Enabled = true
	end
end

1 answer

✓ Accepted answer

In my opinion the easiest way would be to do something along these lines:

local light = script.Parent.SurfaceLight;

while wait() do
	if game.Lighting.TimeOfDay >= "18:00:00" then
		light.Enabled = true;
	elseif game.Lighting.TimeOfDay >= "06:00:00" then
		light.Enabled = false;
	end;
end;

This pretty much just checks the time and sets the light accordingly ** Please note: This is assuming you are using a day night script and it will change when it hits these times **

I hope this helped. If it didn't feel free to ask more questions, or pm me and ask for help if you have any other questions.

This discussion is preserved as it was. New answers, comments, and votes are closed.