This script is supposed to increase the time by one minute every second, so 1 hour in the game is 1 minute in real life. Here is the script:
01 | --[[Details: |
02 | Parent of script is Lighting |
03 | It does not say there is an error in output |
04 | The TimeOfDay property will not change |
05 | The default value of the property is "14:00:00"]] |
06 |
07 | local Lighting = script.Parent |
08 | local hour = 14 |
09 | local minute = 00 |
10 |
11 | function addMinute() |
12 | if minute = = 59 then |
13 | minute = 00 |
14 | if hour = = 23 then |
15 | hour = 00 |
A much simpler way is just to add 1 every second using :SetMinutesAfterMidnight()
.
1 | local lighting = game:GetService( "Lighting" ) |
2 |
3 | while wait( 1 ) do |
4 | local minutes = lighting:GetMinutesAfterMidnight() |
5 | lighting:SetMinutesAfterMidnight(minutes + 1 ) |
6 | print (string.sub(lighting.TimeOfDay, 1 , 5 )) -- If you want to use it in a textlabel |
7 | end |
tostring() is not needed, just put the variable in and it will work. Also, I'd suggest using :SetMinutesAfterMidnight() for a day/night cycle.
01 | local Lighting = script.Parent |
02 | local hour = 14 |
03 | local minute = 00 |
04 |
05 | function addMinute() |
06 | if minute = = 59 then |
07 | minute = 00 |
08 | if hour = = 23 then |
09 | hour = 00 |
10 | else |
11 | hour = hour + 1 |
12 | Lighting.TimeOfDay = hour.. ":" ..minute.. ":00" |
13 | end |
14 | Lighting.TimeOfDay = hour.. ":" ..minute.. ":00" |
15 | else |