TimberWoods / src /ServerScriptService /DayNightManager.server.lua
algorembrant's picture
Upload 88 files
0712d5f verified
-- src/ServerScriptService/DayNightManager.server.lua
local Lighting = game:GetService("Lighting")
local TweenService = game:GetService("TweenService")
-- Day/Night cycle settings
local CYCLE_SPEED = 1 -- 1 = real-time (1 min real = 1 min ingame), higher = faster
local MINUTES_PER_CYCLE = 20 -- Full day-night cycle in real minutes
-- Lighting presets
local Presets = {
Dawn = {
ClockTime = 6,
Ambient = Color3.fromRGB(140, 120, 100),
OutdoorAmbient = Color3.fromRGB(120, 100, 80),
Brightness = 1,
FogColor = Color3.fromRGB(200, 170, 140),
FogEnd = 1500,
},
Day = {
ClockTime = 12,
Ambient = Color3.fromRGB(150, 150, 150),
OutdoorAmbient = Color3.fromRGB(140, 140, 140),
Brightness = 2,
FogColor = Color3.fromRGB(200, 210, 220),
FogEnd = 2000,
},
Dusk = {
ClockTime = 18,
Ambient = Color3.fromRGB(150, 100, 80),
OutdoorAmbient = Color3.fromRGB(130, 90, 70),
Brightness = 1,
FogColor = Color3.fromRGB(200, 140, 100),
FogEnd = 1200,
},
Night = {
ClockTime = 0,
Ambient = Color3.fromRGB(50, 50, 70),
OutdoorAmbient = Color3.fromRGB(30, 30, 50),
Brightness = 0,
FogColor = Color3.fromRGB(40, 40, 60),
FogEnd = 800,
},
}
-- Initialize lighting
Lighting.ClockTime = 6
Lighting.GeographicLatitude = 40
Lighting.GlobalShadows = true
-- Add atmosphere
local atmosphere = Instance.new("Atmosphere")
atmosphere.Density = 0.3
atmosphere.Offset = 0.25
atmosphere.Color = Color3.fromRGB(199, 199, 199)
atmosphere.Decay = Color3.fromRGB(92, 60, 13)
atmosphere.Glare = 0
atmosphere.Haze = 1
atmosphere.Parent = Lighting
-- Add sky
local sky = Instance.new("Sky")
sky.SunAngularSize = 11
sky.MoonAngularSize = 9
sky.Parent = Lighting
-- Add bloom effect
local bloom = Instance.new("BloomEffect")
bloom.Intensity = 0.2
bloom.Size = 24
bloom.Threshold = 0.9
bloom.Parent = Lighting
-- Add color correction
local colorCorrection = Instance.new("ColorCorrectionEffect")
colorCorrection.Brightness = 0
colorCorrection.Contrast = 0.1
colorCorrection.Saturation = 0.15
colorCorrection.TintColor = Color3.new(1, 1, 1)
colorCorrection.Parent = Lighting
-- Add sun rays
local sunRays = Instance.new("SunRaysEffect")
sunRays.Intensity = 0.05
sunRays.Spread = 0.5
sunRays.Parent = Lighting
-- Smooth day/night cycle
local cycleStep = (24 / (MINUTES_PER_CYCLE * 60)) * CYCLE_SPEED
task.spawn(function()
while true do
Lighting.ClockTime = (Lighting.ClockTime + cycleStep) % 24
-- Adjust lighting properties based on time of day
local time = Lighting.ClockTime
if time >= 5 and time < 7 then
-- Dawn transition
local t = (time - 5) / 2
colorCorrection.TintColor = Color3.new(1, 0.9 + t * 0.1, 0.85 + t * 0.15)
sunRays.Intensity = 0.02 + t * 0.06
elseif time >= 7 and time < 17 then
-- Full day
colorCorrection.TintColor = Color3.new(1, 1, 1)
sunRays.Intensity = 0.05
elseif time >= 17 and time < 19 then
-- Dusk transition
local t = (time - 17) / 2
colorCorrection.TintColor = Color3.new(1, 0.95 - t * 0.1, 0.9 - t * 0.2)
sunRays.Intensity = 0.08 - t * 0.06
else
-- Night
colorCorrection.TintColor = Color3.new(0.8, 0.8, 0.95)
sunRays.Intensity = 0
end
task.wait(1)
end
end)
print("Day/Night cycle started")