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 =)
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