Hey. Randomly this day night script quit working unless I manually disable and reenable it in Studio play mode.
-- Scripted by Kept (@xNashCookies) on 2024/05/27
repeat
task.wait()
until
game.Players.LocalPlayer.Character ~= nil
--// SETTINGS //--
local timeTakesSettingNight = 75 -- How much time it takes for the night to end
local timeTakesSettingDay = 300 -- How much time it takes for the day to end
--// TIME SETTINGS (Explorer Tab -> Lighting -> ClockTime) To change settings //--
local AfternoonNight = 17.85 -- When it starts getting dark (17.85 is 17:51 PM)
local morningNight = 6.25 -- From midnight to the sunrise (6.25 is 6:15 AM)
--// NOTE: If you are not familiar with coding, do not change the values below.
local tweenService = game:GetService("TweenService")
local Lighting = game:GetService("Lighting")
local currentTime = Lighting.ClockTime
local timeTakes = timeTakesSettingDay
local TimeRemove = (timeTakes * currentTime) / 24
timeTakes = timeTakes - TimeRemove
local function checkTime()
if Lighting.ClockTime >= AfternoonNight or Lighting.ClockTime <= morningNight then
return "Night"
elseif Lighting.ClockTime < AfternoonNight and Lighting.ClockTime > morningNight then
return "Day"
end
end
while script.Parent.CanAdvanceClock.Value == true do
print("is this even working")
if checkTime() == "Day" then
local cycleTween = tweenService:Create(Lighting, TweenInfo.new(timeTakes, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut), {ClockTime = AfternoonNight})
cycleTween:Play()
if script.Parent.CanAdvanceClock.Value == true then
cycleTween.Completed:Wait()
end
Lighting.ClockTime += .01
timeTakes = timeTakesSettingNight
elseif checkTime() == "Night" then
if Lighting.ClockTime >= AfternoonNight then
print(timeTakes)
local cycleTween = tweenService:Create(Lighting, TweenInfo.new(timeTakes, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut), {ClockTime = 24})
cycleTween:Play()
if script.Parent.CanAdvanceClock.Value == true then
cycleTween.Completed:Wait()
end
Lighting.ClockTime += .01
local substractTime = ((timeTakesSettingNight * (24-AfternoonNight)) / 24)
timeTakes = timeTakesSettingNight - substractTime
elseif Lighting.ClockTime <= morningNight then
local cycleTween = tweenService:Create(Lighting, TweenInfo.new(timeTakes, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut), {ClockTime = morningNight})
cycleTween:Play()
if script.Parent.CanAdvanceClock.Value == true then
cycleTween.Completed:Wait()
end
Lighting.ClockTime += .01
timeTakes = timeTakesSettingDay
end
end
end