MadDog_YT

Day/Night Cycle Creator Studio

Apr 27th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. -- dayLength defines how long, in minutes, a day in your game is. Feel free to alter it.
  2. local dayLength = 12
  3.  
  4. local cycleTime = dayLength*60
  5. local minutesInADay = 24*60
  6.  
  7. local lighting = game:GetService("Lighting")
  8.  
  9. local startTime = tick() - (lighting:getMinutesAfterMidnight() / minutesInADay)*cycleTime
  10. local endTime = startTime + cycleTime
  11.  
  12. local timeRatio = minutesInADay / cycleTime
  13.  
  14. if dayLength == 0 then
  15. dayLength = 1
  16. end
  17.  
  18. repeat
  19. local currentTime = tick()
  20.  
  21. if currentTime > endTime then
  22. startTime = endTime
  23. endTime = startTime + cycleTime
  24. end
  25.  
  26. lighting:setMinutesAfterMidnight((currentTime - startTime)*timeRatio)
  27. wait(1/15)
  28. until false
Add Comment
Please, Sign In to add comment