-- Countdown Script (Client-Side) local ReplicatedStorage = game:GetService("ReplicatedStorage") local countdownLabel = script.Parent -- Update function to display the time in the format 00:00:00:00 (Days:Hours:Minutes:Seconds) local function updateTimer(targetTime) local currentTime = os.time() local remainingTime = targetTime - currentTime if remainingTime == 0 then print("Countdown Complete!") -- Trigger any event end -- Ensure the countdown doesn't go negative if remainingTime < 0 then remainingTime = 0 end -- Calculate days, hours, minutes, and seconds local days = math.floor(remainingTime / (24 * 60 * 60)) local hours = math.floor((remainingTime % (24 * 60 * 60)) / (60 * 60)) local minutes = math.floor((remainingTime % (60 * 60)) / 60) local seconds = remainingTime % 60 -- Format the time as 00:00:00:00 (Days:Hours:Minutes:Seconds) local formattedTime = string.format("%02d:%02d:%02d:%02d", days, hours, minutes, seconds) -- Update the label text countdownLabel.Text = formattedTime end -- Get the target time from the server when the player joins local targetTime = ReplicatedStorage:WaitForChild("GetTargetTime"):InvokeServer() -- Run the timer every second while true do updateTimer(targetTime) wait(1) end
@duckhive-games
9 күн бұрын
-- Countdown Script (Server-Side) local ReplicatedStorage = game:GetService("ReplicatedStorage") local DataStoreService = game:GetService("DataStoreService") local getTargetTimeRemoteFunction = ReplicatedStorage:WaitForChild("GetTargetTime") local countdownDataStore = DataStoreService:GetDataStore("CountdownStore") -- Define the countdown duration (e.g., 7 days in seconds) local countdownDuration = 7 * 24 * 60 * 60 -- function to save the target end time local function saveTargetTime() local currentTime = os.time() -- current time in seconds local targetTime = currentTime + countdownDuration -- target end time in seconds -- Save the targetTime in the DataStore local success, err = pcall(function() countdownDataStore:SetAsync("targetTime", targetTime) end) if not success then warn("Failed to save countdown time:", err) end end -- function to retrieve the target end time local function getTargetTime() local success, targetTime = pcall(function() return countdownDataStore:GetAsync("targetTime") end) if success and targetTime then return targetTime else warn("Failed to retrieve countdown time:", targetTime) return nil end end -- When the client request the target time getTargetTimeRemoteFunction.OnServerInvoke = function() -- Retrieve the target time from the DataStore local targetTime = getTargetTime() -- If targetTime is nil (meaning it's the first join), save the target time if not targetTime then saveTargetTime() -- call this to set the targetTime targetTime = getTargetTime() -- Retrieve it again after saving end return targetTime end
@lofitagen
8 күн бұрын
you have discord sever?
@duckhive-games
7 сағат бұрын
I do - it's exclusive for my Patrons though. You can join for $1 if you're still interested. www.patreon.com/duckhive_
Пікірлер: 6