Attempting to Tween Lighting

Hello,

I am attempting to create a Day/Night cycle script that uses TweenService to smoothly transition between night and day. The time changing works fine with the code provided below. The issue I’ve run into is that the Ambient/OutdoorAmbient while tweening just continues to climb into the thousands, and on the return back it goes down in leaps until it either reaches 0 or the tween ends.

Here is my current code (Yes, I know this is not going to loop…I’m working on the functionality first before adding in the loop to continue day cycles):

local TweenService = game:GetService("TweenService")
local LIGHTING = game.Lighting
local DAYPEAK = 12
local NIGHTPEAK = 24

--Day Settings--

local DAYAMBIENT = Color3.new(120,120,120)
local DAYOUTDOORAMBIENT = Color3.new(175,175,175)

--Night Settings--

local NIGHTAMBIENT = Color3.new(40,40,40)
local NIGHTOUTDOORAMBIENT = Color3.new(0,0,0)

local Info = TweenInfo.new(5)

local Goals1 = 
	{
		ClockTime = DAYPEAK;
		Ambient = DAYAMBIENT;
		OutdoorAmbient = DAYOUTDOORAMBIENT;
	}

local Goals2 =
	{
		ClockTime = NIGHTPEAK;
		Ambient = NIGHTAMBIENT;
		OutdoorAmbient = NIGHTOUTDOORAMBIENT;
	}

local DayTween = TweenService:Create(LIGHTING,Info,Goals1)
local NightTween = TweenService:Create(LIGHTING,Info,Goals2)

wait(1)

DayTween:Play()

wait(1)

NightTween:Play()

My goal is to have it so the Ambient and OutdoorAmbient is transitioned from it’s current position to the target value. Any help is greatly appreciated!

1 Like

I found the issue and resolved it. Instead of using Color3.new I needed to use Color3.fromRGB. Doing this allowed the code to work fine. Thanks anyway! I’ll leave this thread open for anyone that’s curious.

Corrected Code:

local TweenService = game:GetService("TweenService")
local LIGHTING = game.Lighting
local DAYPEAK = 12
local NIGHTPEAK = 24

--Day Settings--

local DAYAMBIENT = Color3.fromRGB(120,120,120)
local DAYOUTDOORAMBIENT = Color3.fromRGB(175,175,175)

--Night Settings--

local NIGHTAMBIENT = Color3.fromRGB(40,40,40)
local NIGHTOUTDOORAMBIENT = Color3.fromRGB(0,0,0)

local Info = TweenInfo.new(5)

local Goals1 = 
	{
		ClockTime = DAYPEAK;
		Ambient = DAYAMBIENT;
		OutdoorAmbient = DAYOUTDOORAMBIENT;
	}

local Goals2 =
	{
		ClockTime = NIGHTPEAK;
		Ambient = NIGHTAMBIENT;
		OutdoorAmbient = NIGHTOUTDOORAMBIENT;
	}

local DayTween = TweenService:Create(LIGHTING,Info,Goals1)
local NightTween = TweenService:Create(LIGHTING,Info,Goals2)

wait(5)

DayTween:Play()

wait(1)

NightTween:Play()
5 Likes