Hello there! i’m trying to make an script, based on Day / Night Cycle Script, so when the day comes it plays the day soundtrack, and same for night time, and their custom settings, but it seems to be not working. Here is an picture of what i need for Night Time.
Hello, so I revised your code. I noticed a few things while I was revising it. The if statements you used weren’t ideal because you had your daytime check inside of your nighttime check.
Also a common rule of thumb I like to use is the moon comes at 18 and the sun rises at 6. With this in mind when creating your if statements you can say that night time either has to be >= 18 and, it has to be < 6. With this in mind you can do:
if lighting.ClockTime > 18 or lighting.ClockTime < 6 then
-- It has to be nightime
else
-- The only other option is for it to be daytime if nighttime was not ran
end
Also, using a 1 line if statement you can create a debounce like this (More info on returning):
if Playing then return end --If something is true then return
--Code down here will only run if playing is not true
The rest of your code works just fine though. Just make sure to remove unnecessary if statements.
Revision
Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
if Lighting.ClockTime > 18 or Lighting.ClockTime < 6 then --If the time is greater than 18 or less than 6 we consider it nighttime
if game.Workspace.Ambient.SummerNight.Playing then return end --You can use whether or not the nighttime ambiance is playing as a debounce
game.Workspace.Ambient.Forest:Stop()
game.Workspace.Ambient.SummerNight:Play()
Lighting.Brightness = 0.65
Lighting.ColorShift_Top = Color3.fromRGB(133, 198, 255)
Atmosphere.Color = Color3.fromRGB(18, 61, 136)
Atmosphere.Haze = 0.65
Clouds.Color = Color3.fromRGB(134, 178, 255)
else
if game.Workspace.Ambient.Forest.Playing then return end --You can also use whether or not the forest ambiance is playing as a debounce
game.Workspace.Ambient.SummerNight:Stop()
game.Workspace.Ambient.Forest:Play()
Lighting.Brightness = 1.5
Lighting.ColorShift_Top = Color3.fromRGB(0, 0, 0)
Atmosphere.Color = Color3.fromRGB(243, 236, 255)
Atmosphere.Haze = 1.61
Clouds.Color = Color3.fromRGB(255, 230, 208)
end
end)
You need to make sure that you have a loop that is changing the clock time. Additionally if you already have code that does that process, then make sure you have the right lighting instances in lighting (i.e. Atmosphere, Sunrays, etc.)
local Lighting = game:GetService("Lighting")
while true do
Lighting.ClockTime += 1
task.wait(1)
end