Countdown not counting to what it is suppose to countdown to

Hey everyone! So today I was working on a little christmas project and I wanted to add a christmas countdown, so I made it, and it works, which is good, but when I looked at the months, it said that there was two months and 24 days, but there is actually 58 days which is not two months, does anyone know how to fix this? here is my script…

local countdownText = script.Parent.CountDown

local day = os.time({year = 2020, month = 12, day = 24, hour = 24, min = 0, sec = 0})

while wait() do
	
	local secondsBetween = os.difftime(day, os.time())
	local dataTable = os.date("!*t", secondsBetween)
	
	local textString = dataTable["month"].."     "..dataTable["day"].."     "..dataTable["hour"].."     "..dataTable["min"].."     "..dataTable["sec"]
	countdownText.Text = textString
	
	if secondsBetween <= 0 then break end
end

Have you tried putting prints in to see the values to check they ate as you expect?

Nope, don’t even know where I would put the prints.

According to the Roblox Developer Hub,

If provided a table formatted similarly to that returned by os.date , it will return the number of seconds since that time instead.

So, the countdown would just be the negative of os.time({year = 2020, month = 12, day = 24, hour = 24, min = 0, sec = 0}).

oh, so I would do

os.time({year = -2020, month = -12, day = -24, hour = -24, min = 0, sec = 0})

OHH, I get what your saying… I was think of something else haha.

Ok so when I do

os.date

I get an error saying Workspace.Decor.CountDownBoard.Board.SurfaceGui.ChristmasCountDown:3: invalid argument #1 to ‘date’ (string expected, got table)

I know that I am suppose to put a string in there but I already have a string that is textString, So I am not really sure what I am suppose to do.

You can always try a more conventional approach by formatting it from seconds to the date you want. Something similar to this: time - Lua 4 script to convert seconds elapsed to days, hours, minutes, seconds - Stack Overflow. I tested something similar with your variable “SecondsBetween” and it worked perfectly.

I got it all figured out, Thanks for the help tho :)))

I’d probably change this to:
while game:GetService("RunService").Heartbeat:Wait() do

I got it working, but I will try that thank you :)))

Do you mind explaining to me what this does? Is it just a safer way to use while wait() do?

btw, I’ve seen your games and stuff on twitter, there cool, keep it up :)))