Advertisement
Dfgjfj

Day/Night cycle with moon phase script

Feb 7th, 2025
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.23 KB | None | 0 0
  1. local Time = 10 -- how much time you want the day last, example: 10 mean 10 minute in real life
  2. local converted = 24 / Time / 60 / 2
  3. local clocktime = 7 -- you can choose when server start, what clock time should be example 7 mean 7 am in your game
  4. local PhaseIndex = 0
  5. local DayFinished = false
  6. local MoonPhase = {
  7. "rbxthumb://type=Asset&id=16106114762&w=420&h=420",-- you can add more, but make sure you follow the format
  8. "rbxthumb://type=Asset&id=16106117102&w=420&h=420",
  9. "rbxthumb://type=Asset&id=16106102598&w=420&h=420",
  10. "rbxthumb://type=Asset&id=5385993191&w=420&h=420"
  11. }
  12.  
  13. game:GetService("RunService").Heartbeat:Connect(function(frameTime)
  14.     clocktime = (clocktime + frameTime * converted) % 24
  15. end)
  16.  
  17. while true do
  18.     game.Lighting.ClockTime = clocktime
  19.     if  clocktime >= 17 and not DayFinished then
  20.         DayFinished = true
  21.         PhaseIndex = (PhaseIndex % #MoonPhase) + 1
  22.         if game.Lighting:FindFirstChildOfClass("Sky") then
  23.             game.Lighting:FindFirstChildOfClass("Sky").MoonTextureId = MoonPhase[PhaseIndex]
  24.         else
  25.             print("Create a sky, or moon phase wont work")
  26.         end
  27.     elseif clocktime <= 17 then
  28.         DayFinished = false
  29.     end
  30.    
  31.    
  32.     task.wait(1)
  33. end
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement