I recently managed to fix my day/night cycle to loop properly, but now I'd like some help on smoothly changing the OutdoorAmbient and Ambient. I assume this will use lerp which I'm inexperienced in.
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) elseif 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 if MinutesAfterMidnight >= 1440 then MinutesAfterMidnight = 0 end end
I am not experienced in lerp, and I doubt it will work in this case, since I'm pretty sure it's for CFrame and Vector3, anyways, Like Thundermaker300 said, I am using TweenService.
local MinutesAfterMidnight = 0 local TweenService = game:GetService("TweenService") -- Puts the TweenService into a quickly accessable variable local goal1 = { -- The changes that occur at day Brightness = 1, OutdoorAmbient = Color3.new(97/255, 97/255, 97/255), Ambient = Color3.new(5/255, 5/255, 5/255)} goal2 = { -- The changes that occur at night Brightness = 0, OutdoorAmbient = Color3.new(5/255, 5/255, 5/255), Ambient = Color3.new(2/255, 2/255, 2/255)} info = TweenInfo.new(2,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut) -- Gives the tween info about it's job. (seconds, EasingStyle, EasingDirection, RepeatCount, Reverses, Delay). day = TweenService:Create(game.Lighting,info,goal1) night = TweenService:Create(game.Lighting,info,goal2) while true do game.Lighting:SetMinutesAfterMidnight(MinutesAfterMidnight) MinutesAfterMidnight = MinutesAfterMidnight + 10.5 wait(0.1) if MinutesAfterMidnight == 6 * 60 then -- I did this since it's inefficient to run the tween every time the while loop goes thorugh, the tween would be called all of the time, literally. day:Play() elseif MinutesAfterMidnight == 18 * 60 then -- Same reason here. night:Play() end if MinutesAfterMidnight >= 1440 then MinutesAfterMidnight = 0 end end
This should work, I tested it out and it works seamlessly. It takes 2 seconds to change from the night to day, or day to night. One of the comments has info on how to change that number, but I have it at 2. If this answered this question please mark it as the answer that answered your question.