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

I need help fixing my day/night cycle script. Does anybody have any ideas?

Asked by 5 years ago

I currently have one issue that needs to be fixed and one subject I need advice on. To put it simply whenever this script runs it works fine for a single cycle of the sun and moon, but then it finds itself getting stuck on the night mode. The second part I need help with is finding some way to tween this so it's a much smoother transition.

local MinutesAfterMidnight = 0

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

    if MinutesAfterMidnight >= 6 * 60 or 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
0
Reset the minutes at the end to put it back at 0 and keep the loop going. TiredMelon 405 — 5y
0
Thank you, I was partially confused by this until I realized by reset you mean with an if statement if it is equal to or above 1440. Thank you for your help! Etherial_Combatant 4 — 5y

Answer this question