Need help having this code explained as to how it DOES work properly without any errors?
So I have been following some of the scripting tutorials on the Roblox wiki and need some better explanation to this code.
So basically I have made a day/night cycle which I completely understand how that works and everything in that department is completely fine, but here is the code for it anyways:
1 | minutesAfterMidnight = 0 |
4 | game.Lighting:SetMinutesAfterMidnight(minutesAfterMidnight) |
5 | minutesAfterMidnight = minutesAfterMidnight + 10 |
6 | print (minutesAfterMidnight) |
Yes I know this cycles through days and nights very quickly, but that is for testing purposes.
Now here is the part I do not understand; I have made a street light type-thing that turns itself off and back on depending on the time.
Here is the code for it:
01 | lightPart = script.Parent |
02 | pointLight = lightPart.PointLight |
05 | if game.Lighting:GetMinutesAfterMidnight() > 60 * 6 then |
06 | lightPart.Material = "Plastic" |
07 | pointLight.Enabled = false |
08 | if game.Lighting:GetMinutesAfterMidnight() > 60 * 18 then |
09 | lightPart.Material = "Neon" |
10 | pointLight.Enabled = true |
I would like to say that I did all of this without even looking at the tutorial for probably a couple days (I do this to challenge myself), but I realize that I don't think this script should work, but it does.
The reason I don't understand why this code DOES work is just because I'm checking the specific amount of minutes past midnight. Basically my day/night cycle will make it be thousands upon thousands of minutes past midnight, yet the script still works just fine. Shouldn't it just stay turned on because the minutes after midnight is indeed far greater than 60*18?
There is one more part I do not understand, which is why don't I need to check and make sure the minutes after midnight is also less than a value. Like make sure minutes after midnight is greater than 6 am but ALSO less than 6 pm?
Also I'm not looking for answers like, "That's just how it works."
I hope I didn't make this too long. I hope someone can explain to me these things.
Anyways, thank you for reading.