Day / Night script explanation

Hi, I found this script from the toolbox. but I don’t know how it works, it’s basically a day/night script, but I don’t know how it works. Please explain this script

local Lighting = game:GetService("Lighting")

while wait(1) do
	Lighting:SetMinutesAfterMidnight(Lighting:GetMinutesAfterMidnight() + 1)
end
1 Like

That script is basically a loop that changes the day time every second.

while wait(1) do --Every "wait(1)", execute:
    Lighting:SetMinutesAfterMidnight(Lighting:GetMinutesAfterMidnight() + 1) --Day time + 1
end --End and start again
1 Like

No no, I meant what Lighting:SetMinutesAfterMidnight(Lighting:GetMinutesAfterMidnight() + 1) does

GetMinutesAfterMidnight() function returns how many minutes passed since the midnight.
SetMinutesAfterMidnight(Param1) function changes Lighting.TimeOfDay and Lighting.ClockTime properties of the LightingService reletive to Param1 value (Param1 must be in minutes).
while wait(1) do Lighting:SetMinutesAfterMidnight(Lighting:GetMinutesAfterMidnight() + 1) end changes the time by +1 minute every second by adding 1 to the value returned by GetMinutesAfterMidnight() function then changing the time by one minute forward with the use of SetMinutesAfterMidnight(Param1) function which in this case Param1 is the result of Lighting:GetMinutesAfterMidnight() + 1 operation.

1 Like

Yup, you can check the API Pages here: