So, the goal of this script is for the server to play Sound every day at 11:59:40 PM EST, but it’s not working and I’ve no idea why. How would I edit the code so it successfully plays the sound at the specified real world time?
local RunService = game:GetService("RunService")
local Sound = game.Workspace.Bong
local DaysInMonth = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
function GetNextTimestamp()
local Now = os.date("!*t")
local NextDay = (Now.day + 1)
local NextMonth = Now.month
local NextYear = Now.year
if NextDay > DaysInMonth[NextMonth] then
NextDay = 1
NextMonth += 1
if NextMonth > 12 then
NextMonth = 1
NextYear += 1
end
end
local Timestamp = os.time({
year = NextYear,
month = NextMonth,
day = NextDay,
hour = 23,
min = 59,
sec = 40,
})
return Timestamp - 5 * (60 * 60) -- EST calculations
end
RunService.Heartbeat:Connect(function()
local NextTimestamp = GetNextTimestamp()
if os.time() >= NextTimestamp then
if not Sound.IsPlaying then
Sound:Play()
end
end
end)