hey, I don't have experience with lighting so this code may be incorrect, but I'm fairly certain the general concept will have to be loop that changes the rgb values overtime. I found a nice looking method on the Color3 documentation called Color3:lerp().
local function shiftTint(rgbStart, rgbEnd, time)
for alpha = 0, 1, 1 / (time * 10) do
Color.TintColor = rgbStart:lerp(rgbEnd, alpha)
wait(0.1)
end
end
time will be the transition time in seconds. I haven't tested it so let me know if there's a problem
edit: PS, you should be using local when declaring variables even on the outside, it's neater :)
edit 2: from what I see, your brightness is dependent on time while your color is not, so it seems wasteful to create a new color every time. what I would do is make a variable that shows the time of day. every loop, you will check the time passed, and once it reaches your threshold, change that value to something like "night", "day", etc. this has the bonus of making it easier to understand.
if your time was in fact changed, this is where you run that function I gave you earlier, using the current tint and the new tint.
after all that, calculate your brightness like you did already, depending on the time of day. I would make an object to organize the data for each time of day. here's what I would do. (remember, haven't used lighting before so I can't optimize everything :) )
function shiftTint(rgbStart, rgbEnd, time)
for alpha = 0, 1, 1 / (time * 10) do
Color.TintColor = rgbStart:lerp(rgbEnd, alpha)
wait(0.1)
end
end
local Settings = {
Night = {
Tint = Color3.fromRGB (192, 44, 255),
Brightness = function(t) return t / 180 * -0.2 end
},
Day = {
Tint = Color.TintColor = Color3.fromRGB (144, 144, 144),
Brightness = function(t) return -(0.8 - t / 180 * 0.2) end
},
Default = {
Tint = Color3.fromRGB (192, 44, 255),
Brightness = function(t) return -0.2 end
}
}
local setting = Settings.Default
local LOOPTIME = 0.05
local MINS_PER_DAY = 60 * 24
local time = game.Lighting:GetMinutesAfterMidnight()
while true do
time = (time + minutesPerSecond * LOOPTIME) % MINS_PER_DAY
game.Lighting:SetMinutesAfterMidnight(time)
if RealisticDarkness == true and (time >= 1080 or time <= 360) then
minsPastSix = time - 1080
if minsPastSix < 0 then
minsPastSix = 360 + time
end
local newSetting
if minsPastSix <= 180 then
newSetting = Settings.Night
elseif MinsPastSix >= 540 then
newSetting = Settings.Day
else
newSetting = Settings.Default
end
if setting ~= newSetting then
shiftTint(setting.Tint, newSetting.Tint, 3)
setting = newSetting
end
Color.Brightness = setting.Brightness(time)
end
wait(LOOPTIME)
end
also, I think that the people in the comments had a better solution that I did. tweenservice is built for smooth transitions, and I expect it works on color too (I didn't know that when I posted). my solution is a bit hackier, so I suggest you look into tweenservice as well :)
2 comments
TweenService.
^ Also Hue