Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Broken Day/Night cycle script. Can anybody help me fix it and possibly make it smoother?

Asked by 5 years ago
Edited 5 years ago

The problem I'm having with my script is that on the second cycle of the moon, it permanently sets the outdoor ambience and ambience to the dark version and does not fix itself. As well as that I would appreciate tips on how to make it a smoother transition. Here is the code I'm having trouble with.

local MinutesAfterMidnight = 0

while true do
    game.Lighting:SetMinutesAfterMidnight(MinutesAfterMidnight)
    MinutesAfterMidnight = MinutesAfterMidnight + 10.5
    wait(0.1)

    if MinutesAfterMidnight >= 6 * 60 and MinutesAfterMidnight <= 18 * 60 then
        game.Lighting.Brightness = 1
        game.Lighting.OutdoorAmbient = Color3.new(97/255, 97/255, 97/255)
        game.Lighting.Ambient = Color3.new(5/255, 5/255, 5/255)
    end

    if MinutesAfterMidnight >= 18 * 60 or MinutesAfterMidnight <= 6 * 60 then
        game.Lighting.Brightness = 0
        game.Lighting.OutdoorAmbient = Color3.new(5/255, 5/255, 5/255)
        game.Lighting.Ambient = Color3.new(2/255, 2/255, 2/255)
    end
end

As a side note after looking at the world lighting while running it, on the second moon cycle the OutdoorAmbient and Ambient did not change when the sun came up. Also the sky itself seemed to have darkened halfway through the night.

1 answer

Log in to vote
1
Answered by
valchip 789 Moderation Voter
5 years ago

Try this:

l = game:service("Lighting") 
r = game:service("RunService")

while true do 
l:SetMinutesAfterMidnight(l:GetMinutesAfterMidnight()+1) 
wait(.2)
end 
0
Bad idea, it won't even change. Time passes just fine with the code I have, it's the loop itself when it comes to changing the Ambient and OutdoorAmbient that's the problem. Etherial_Combatant 4 — 5y
0
Never mind I just found the solution! It turns out I needed to use an if statement to reset the MinutesAfterMidnight back to 0 if it greater than or equal to 1440 or 24 * 60. Thanks for trying to help though! :) Etherial_Combatant 4 — 5y
Ad

Answer this question