CCCPaste

GlobalCountdown ServerScriptService

--Script in ServerScriptService
local DataStoreService = game:GetService("DataStoreService")
local countdownStore = DataStoreService:GetDataStore("GlobalCountdownStore")
local countdownPart = workspace:WaitForChild("CountdownPart")

local targetDate = os.time({
	year = 2026,
	month = 1,
	day = 1,
	hour = 0,
	min = 0,
	sec = 0
})


local countdownEndTime = nil

local function initializeCountdown()
	local success, storedEndTime = pcall(function()
		return countdownStore:GetAsync("endTime")
	end)

	if success and storedEndTime then
		countdownEndTime = storedEndTime
	else
		countdownEndTime = targetDate
		pcall(function()
			countdownStore:SetAsync("endTime", countdownEndTime)
		end)
	end
end

local function updateCountdown()
	local currentTime = os.time()
	local timeRemaining = countdownEndTime - currentTime

	timeRemaining = math.max(0, timeRemaining)

	for _, player in ipairs(game.Players:GetPlayers()) do
		game.ReplicatedStorage.CountdownEvent:FireClient(player, timeRemaining)
	end
end

initializeCountdown()

while true do
	updateCountdown()
	wait(1)
end