SunRay.Spread doesn't tween with the in-game's time

Goal:
So I want to tween the SunRays that if it reaches Sunset/Sunrise times, the SunRay’s Spread would be increased

and then when the time is at Normal Day times, the SunRay Spread would decrease…

Issue:


(The time in the Video is moving faster so that waiting for the Sunset wouldn’t take long)

The SunRay’s Spread doesn’t seem to have increased
I used both " game.Lighting " and " game:GetService(“Lighting”) " but it seems to not work either way…

Could it be that tween doesn’t work for SunRay’s Spread Value?

The Full Script is:


local dayLength = 1
local cycleTime = dayLength*60
local minutesInADay = 24*60

L = game:GetService("Lighting")
Light = game.Lighting

local startTime = tick() - (L:getMinutesAfterMidnight() / minutesInADay)*cycleTime
local endTime = startTime + cycleTime

local timeRatio = minutesInADay / cycleTime

if dayLength == 0 then
	dayLength = 1
end

repeat
	local currentTime = tick()
	
	if currentTime > endTime then
		startTime = endTime
		endTime = startTime + cycleTime
	end
	
	L:setMinutesAfterMidnight((currentTime - startTime)*timeRatio)
	wait(1/15)
until false


TS = game:GetService("TweenService")
TI = TweenInfo.new(20,Enum.EasingStyle.Circular,Enum.EasingDirection.InOut,0,false,0)
TI2 = TweenInfo.new(.25,Enum.EasingDirection.Linear)

Col_Correct = game.Lighting.ColorCorrection

Tween_Sunset = TS:Create(Col_Correct, TI, {TintColor = Color3.fromRGB(255, 186, 90)})
Tween_Normal = TS:Create(Col_Correct, TI, {TintColor = Color3.fromRGB(255, 255, 255)})
Tween_Night = TS:Create(Col_Correct, TI, {TintColor = Color3.fromRGB(221, 169, 227)})


T_Bright_Day = TS:Create(Light, TI, {Brightness = 1})
T_Bright_Night = TS:Create(Light, TI, {Brightness = 0})


Day_Am = Color3.fromRGB(56, 70, 70)
Sunset_Am = Color3.fromRGB(255, 179, 0)
Night_Am = Color3.fromRGB(47, 24, 60)

T_Day_Am = TS:Create(Light, TI, {Ambient = Color3.fromRGB(90, 100, 100)})
T_Night_Am = TS:Create(Light, TI, {Ambient = Color3.fromRGB(45, 14, 65)})
T_Sunset_Am = TS:Create(Light, TI, {Ambient = Color3.fromRGB(255, 168, 80)})

T_Day_Am_Out = TS:Create(Light, TI, {OutdoorAmbient = Color3.fromRGB(56, 70, 70)})
T_Night_Am_Out = TS:Create(Light, TI, {OutdoorAmbient = Color3.fromRGB(39, 0, 60)})
T_Sunset_Am_Out = TS:Create(Light, TI, {OutdoorAmbient = Color3.fromRGB(255, 179, 0)})

SR = Light.SunRays
T_SR_Norm = TS:Create(SR.Spread, TI2, {Spread = 0.5})
T_SR_Set = TS:Create(SR.Spread, TI2, {Spread = 1})

Atmsp = Light.Atmosphere
T_Atmsp_Day = TS:Create(Atmsp, TI2, {Density = 0.35})
T_Atmsp_Night = TS:Create(Atmsp, TI2, {Density = 0.525})

--T_Sat = TS:Create(Col_Correct, TI2, {Saturation = 1})
--T_Unsat = TS:Create(Col_Correct, TI2, {Saturation = 0})

day = false
night = false
nextDay = true
notsunset = true
notsunrise = true

while true do

	wait(1)
	local CT = game.Lighting.ClockTime

	if not nextDay and CT < 3 then
		-- Reset day flag each time clock rolls over
		day = false
		night = true
		nextDay = true
		notsunset = true
		notsunrise = true

	elseif notsunrise and not day and CT > 5.8 then
		print("Setting Sunrise")

		notsunrise = false

		T_Bright_Day:Play()

		T_Sunset_Am:Play()
		T_Sunset_Am_Out:Play()

		Tween_Sunset:Play()
		T_SR_Set:Play()
		--T_Sat:Play()

	elseif nextDay and not day and CT > 6.5 then
		print("Setting Day")

		day = true
		night = false

		T_Day_Am:Play()
		T_Day_Am_Out:Play()

		Tween_Normal:Play()
		
		T_Atmsp_Day:Play()
		T_SR_Norm:Play()
		--T_Unsat:Play()

	elseif notsunset and CT > 17 then
		print("Setting Sunset")

		notsunset = false

		T_Sunset_Am:Play()
		T_Sunset_Am_Out:Play()

		Tween_Sunset:Play()
		T_SR_Set:Play()
		--T_Sat:Play()

	elseif day and CT > 17.8 then

		print("Setting Night")

		day = false
		night = true
		nextDay = false

		T_Bright_Night:Play()

		T_Night_Am:Play()
		T_Night_Am_Out:Play()

		Tween_Night:Play()

		T_Atmsp_Night:Play()
		T_SR_Norm:Play()
		--T_Unsat:Play()

	end
end

I feel like this script is in the right direction to my goal of making a Day/Night Cycle, but not sure on what I could be doing wrong on the SunRays Part.

I want to know what the issue could be so I can fix it

and possibly learn more about Tweening pretty much everything under the Game’s Lightings to make a really nice Day/Night Cycle at some point.

I don’t know why your tween isn’t working, but you could just simply use math.clamp and a bit of math to get the result I think you’re looking for. Also, is the actual property changing at all or is it an issue with the tween not moving it? If the property is not moving at all during the cycle, check if the code for the tween is actually running or not using prints. But, if the property is changing then I would guess this is simply not editable in real-time (such as other properties like Lighting.Technology)

1 Like