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

Light on at certain times of day?

How would you make a light turn on between lets say... 17:00:00 and 08:00:00 and for the time from 08:00:00 to 17:00:00 its off??

And how would you edit the script to make the light flash between the of 17:00:00 and 08:00:00? I've tried and dosent work, heres my script;

while true do
	if game.Lighting.TimeOfDay >= "17:00:00" then
		repeat
			game.Workspace.Light.PointLight.Enabled = true
			wait (2)
			game.Workspace.Light.PointLight.Enabled = false
		
		if game.Lighting.TimeOfDay >= "08:00:00" then
		game.Workspace.Light.PointLight.Enabled = false

Notes: The script is in a block, its a normal script, and im using 'PointLight' for the lighting.. Thanks =)

4 comments

0

You did not add any kind of 'end' to end the blocks of code, that is the main problem in your script.

0

I've added an 'end' to line 10, makes no difference, If I add one after line 6 It says "expected until(to close to repeat at line 3), got 'end' ???

0

A 'repeat' loop requires an 'until == condition', not an 'end'.

0

I've tried many variations of this script, still dosent work :l

1 answer

✓ Accepted answer

What you're trying to do is compare a string with a numerical comparison. What you need to do is use game.Lighting:GetMinutesAfterMidnight() to calculate. Midnight is considered "00:00:00" in the time format.

"17:00:00" happens to be 1020 minutes after midnight, and "08:00:00" is 480 minutes after midnight.

Simple formula to get minutes after midnight, assuming "hh:mm:ss":

h * 60 + m + (s / 60) You will likely never need the s.

Also, change the code to do this:

while true do
	local minutes = game.Lighting:GetMinutesAfterMidnight()

	if minutes >= 1020 or minutes <= 480 then
		-- code if it's night time
	else
		-- code if it's day time
	end

	wait()
end

1 comment

0

It works, Cheers man! =D

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