Countdown timer not displaying the static text

Hello. I was re-scripting the countdown timers in the game to display a text when it hits that specified time.
However, it doesn’t display, and instead it shows the countdown at 0d:0h:0m:0s.


Script:

local countdownGui = script.Parent
local countdownText = countdownGui:WaitForChild("TextLabel")


local day = os.time({year = 2023, month = 12, day = 9, hour = 1, min = 57, sec = 30})
local current = os.time()

while wait() do
	if current >= day then
		countdownText.Text = "Gifts are opened! Merry Christmas!"
	elseif current <= day then
		local secondsBetween = os.difftime(day, os.time())

		local seconds = secondsBetween % 60
		local minutes = math.floor(secondsBetween % (60*60) / 60)
		local hours = math.floor(secondsBetween % (60*60*24) / (60*60))
		local days = math.floor(secondsBetween / (60*60*24))

		local textString = "Gifts opening in" .. days .. "d:" .. hours .. "h:" .. minutes .. "m:" .. seconds .. "s"
		countdownText.Text = textString

		if secondsBetween <= 0 then break end
	end
end
1 Like

After you break out of the loop, you can set the text to whatever you desire.

... previous code ...
countdownText.Text = "Countdown finished";

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.