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

{SOLVED} Lights only on at night?

I have this so far, I know I'm missing the checking part but I don't know how to do it, I'm new to scripting.

function timeFix()
	if game.Lighting.TimeOfDay >= "00:00:00" and game.Lighting.TimeOfDay <= "06:00:00"
	or game.Lighting.TimeOfDay  >= "18:00:00"
	then script.Parent.Enabled = true
	else
	script.Parent.Enabled = false
	end
end

The parent is a spotlight, the rest is pretty self explanatory.

1 answer

✓ Accepted answer

You're attempting to compare two strings as if they were numbers. Rather than using TimeOfDay, use the GetMinutesAfterMidnight() method instead.

function timeFix()
	minutes = game.Lighting:GetMinutesAfterMidnight()
	if minutes >= 0 and minutes <= 360 or minutes >= 1080 then
	script.Parent.Enabled = true
	else
	script.Parent.Enabled = false
	end
end

while wait(1) do timeFix() end --This will cause the timeFix() function to run once every second.

4 comments

0

Silly mistake. I forgot a space. Edited.

0

How can I get it to automatically update itself? At the moment it doesn't turn off automatically when it becomes dark.

0

Added it to my answer.

0

You're the best. Thanks.

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