Hi, i'm trying to create a day/night script that changes the ambient of the lighting ( works fine ) - In conjunction with this, I decided to display the Day and Time in a GUI which every player can see..
What works:
Day/Night Ambient Changes Message is sent to all users
What doesn't work: The day doesn't change. - It's currently stuck on a Monday even though the time goes back 00:00...
My scripts:
Day/Night - ambient
L = game:GetService("Lighting")
while true do
wait(.1)
T = L:GetMinutesAfterMidnight()
L:SetMinutesAfterMidnight(T + .1)
if T < 300 then --Night time, after midnight.
game.Lighting.OutdoorAmbient = Color3.new(30/255,30/255,30/255)
elseif T > 300 and T < 390 then --Dawn, sun rise.
game.Lighting.OutdoorAmbient = Color3.new((30+(T-300)/1.5)/255,(30+(T-300)/1.5)/255,(30+(T-300)/1.5)/255)
elseif T > 390 and T < 600 then --Morning.
game.Lighting.OutdoorAmbient = Color3.new((90+(T-390)/7)/255,(90+(T-390)/7)/255,(90+(T-390)/7)/255)
elseif T > 600 and T < 840 then --Day time.
game.Lighting.OutdoorAmbient = Color3.new(120/255,120/255,120/255)
elseif T > 840 and T < 1050 then --Afternoon.
game.Lighting.OutdoorAmbient = Color3.new((120-(T-840)/7)/255,(120-(T-840)/7)/255,(120-(T-840)/7)/255)
elseif T > 1050 and T < 1140 then --Evening, sun set.
game.Lighting.OutdoorAmbient = Color3.new((90-(T-1050)/1.5)/255,(90-(T-1050)/1.5)/255,(90-(T-1050)/1.5)/255)
elseif T > 1140 then --Night time, before midnight.
game.Lighting.OutdoorAmbient = Color3.new(30/255,30/255,30/255)
end
end
Day and Time script:
local Lighting = game.Lighting
local DayTick = 1
local Days = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}
Lighting:GetPropertyChangedSignal('ClockTime'):Connect(function()
local Hours = tonumber(string.sub(Lighting.TimeOfDay, 1, 2)) -- Gets the hours, turns 05 --> 5
local Minutes = string.sub(Lighting.TimeOfDay, 4, 5) -- Gets the minutes, keeps the extra 0
local String = '%s:%s %s'
if Lighting.ClockTime >= 13 and Lighting ~= 0 then -- It's between 1pm and 11:59pm
String = String:format(Hours - 12, Minutes, 'pm')
elseif Lighting.ClockTime >= 12 and Lighting.ClockTime < 13 then -- It's between 12pm and 12:59pm
String = String:format(Hours, Minutes, 'pm')
-- Clock = 0 - Change day...
elseif Lighting.ClockTime == 0 and DayTick ~= 7 then
String = String:format(12, Minutes, 'am')
DayTick = DayTick+1
elseif Lighting.ClockTime == 0 and DayTick == 7 then
String = String:format(12, Minutes, 'am')
DayTick = 1
elseif Lighting.ClockTime >= 0 and Lighting.ClockTime < 1 then -- It's between 12:00am and 12:59am
String = String:format(12, Minutes, 'am')
else -- It's between 1:00am and 11:59 am
String = String:format(Hours, Minutes, 'am')
end
--This sends the Day and time to a GUI ( this is fine don't touch )
local TheText = (Days[DayTick].. ", ".. String)
game.ReplicatedStorage.TimeDay:FireAllClients(TheText)
end)
Please help as I have no idea why the day is not ticking over..
Thank you!
