Window Light Fade Script

I’m trying to fade the colour of a window depending on if it’s day or night. But I don’t know how to use a repeat loop correctly. Can you guys help? Here is my code so far:

local window = script.Parent
local lighting = game.Lighting
local R = 248
local G = 217
local B = 109

game.Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
	
	if lighting.ClockTime >= 17.6 or lighting.ClockTime <= 6.3 then
		window.Material = Enum.Material.Neon
		repeat 
			window.Color =  Color3.fromRGB(R+1,G+1,B+1)
			wait(0.001)
		until
			window.Color == Color3.fromRGB(248,217,109)
		end

	if lighting.ClockTime >= 6.3 or lighting.ClockTime <= 17.6 then
		window.Material = Enum.Material.SmoothPlastic
		repeat 
			window.Color =  Color3.fromRGB(R-1,G-1,B-1)
			wait(0.001)
		until
		window.Color == Color3.fromRGB(49, 49, 49)
	end

u forgot to add end) at the end

1 Like

Ok, it’s changed colour but it happens immediately when I run the sim, rather than waiting for the time to be 17.6. It worked without the repeat loop when it was just

if lighting.ClockTime >= 17.6 or lighting.ClockTime <= 6.3 then
		window.Color = Color3.fromRGB(248,217,109)
		window.Material = Enum.Material.Neon
	else
		window.Color = Color3.fromRGB(63,94,89)
		window.Material = Enum.Material.SmoothPlastic
	end

So I don’t understand why it happens

My honest constructive feedback; this code is very redundant.

I would recommend the use of TweenService, instead of repeating RGB math.

example:

local TS = game:GetService("TweenService")
TS:Create(window, TweenInfo.new(1), {Color = Color3.fromRGB(248, 217, 109) }):Play()

Here is the API reference:

How should I implement this into my existing code?

1 Like

You can do it like this, might need to do some changes to the timing though.

1 Like