Hi,
I have this script in ServerScriptService that runs the hours and the day. I was wondering if it’s possible to save the time in a datastore so that players can join and leave the server and it doesn’t reset to 8o’ clock like in the script?
SSS:
local DayLength = 1440
local InitialTime = 8
local days = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}
local RS = game:GetService("RunService")
local CurrentDay = 1
local playerList = {}
local start = tick()-(InitialTime/24*DayLength)
RS.Stepped:Connect(function()
local t = (tick()-start)/DayLength*24
if t >= 24 then
start = tick()
CurrentDay = math.fmod(CurrentDay, 7)+1
end
game.Lighting.ClockTime = math.fmod(t, 24)
local hours = math.floor(t % 24)
local minutes = math.floor((t % 24 - hours) * 60)
local period = (hours >= 12) and "PM" or "AM"
hours = (hours % 12)
if hours == 0 then hours = 12 end
for i, plr in pairs(playerList) do
local day = plr.PlayerGui.TimeGui.Day
local Time = plr.PlayerGui.TimeGui.Time
day.Text = days[CurrentDay]
Time.Text = string.format("%02d:%02d %s", hours, minutes, period)
end
end)
game.Players.PlayerAdded:Connect(function(plr)
plr.PlayerGui:WaitForChild("TimeGui")
table.insert(playerList, plr)
end)
game.Players.PlayerRemoving:Connect(function(plr)
if table.find(playerList, plr) then
table.remove(playerList, table.find(playerList, plr))
end
end)