Why is my Countdown showing 2 Hours in Studio, but 0 In-game?

Hello! I am having a problem where my Countdown is showing the “Rejoin!” Text before the countdown ended inside Game? Inside Studio, It shows 2 hours but in-game is shows the Text it shows after it hits 0. Why is it doing this?

What I mean:
image
In game ^
image
In Studio ^

Here is the script I am using for it

wait()

local MF = math.floor
local Next = next 
local Tick = tick 
local Wait = wait
local Stop = 0
local Timer = 0.5

while true do Wait(Timer) 
wait()
local Time = 1634855245 - Tick()
local Days = MF((Time / 60 / 60 / 30) % (250 + 0.250)) 
local Hours = MF((Time / 60 / 60) % 30) 
local Minutes = MF((Time / 60) % 60) 
local Seconds = MF(Time % 60) 

if Stop == 0 then

script.Parent.Time.Text = Days..":"..Hours.. ":"..Minutes..":"..Seconds.." "
end

if Days==0 and Hours==0 and Minutes==0 and Seconds==0 or Time < 0 then
Stop=0
script.Parent.Time.Text = "Rejoin!"
	end
end 

Any help will be appreciated!

Just to ask make use your game published. Another thing is it should be tick() with lowercase. Not sure why, if this is your entire script how come you have if Stop = 0 when stop doesn’t change within the script you showed which is a bit odd. Just one more thing to point out is wouldn’t Time always be a negative? Unless you want it that way?

The timer could be improved slightly. If this is a global timer, I’m not how to help you there, but if it’s a server, I can help you. Of course you can add this into a global timer if you want.

local AMOUNT_OF_TIME = 3600 -- 1 hour in seconds

local textLabel = script.Parent.Time


for i = AMOUNT_OF_TIME, 0, -1 do

   -- Not sure if this is the best way but seems like the only way I can think off
   local Days = math.floor(i/60/60/60)
   local Hours = math.floor(i/60/60) 
   local Minutes = math.floor(i/60)
   local Seconds = math.floor(i%60)
   
   textLabel.Text = string.format("%02i:%02i:%02i:%02i", Days, Hours, Minutes, Seconds)

   task.wait(1) -- Waits 1 second
end

-- Anything after here will run after the timer has been completed.
print("Timer Completed")
textLabel.Text = "Rejoin" -- ? You could have this if you need as well

I am trying to do a global timer. No matter what timer I do, it still does the same thing that I listed in this post.

I figured out the problem, it’s just the timestamp, if you change it to something else, it may actually work. Perhaps you could use a timestamp converter to help you.

Here’s the one I used personally that helps: https://timestamp.online

Okay so I changed to it to this

wait()

local MF = math.floor
local Next = next 
local Tick = tick 
local Wait = wait
local Stop = 0
local Timer = -1

while true do Wait(Timer) 
	wait()
	local Time = 1634900000 - Tick()
	local Days = MF((Time / 60 / 60 / 30) % (250 + 0.250)) 
	local Hours = MF((Time / 60 / 60) % 30) 
	local Minutes = MF((Time / 60) % 60) 
	local Seconds = MF(Time % 60) 

	if Stop == 0 then

		script.Parent.Time.Text = Days..":"..Hours.. ":"..Minutes..":"..Seconds.." "
	end

	if Days==0 and Hours==0 and Minutes==0 and Seconds==0 or Time < 0 then
		Stop=0
		script.Parent.Time.Text = "Rejoin!"
	end
end 

This is what it shows in studio
image
And this is what it shows in Game
image
It’s still a 4-hour difference, how can I fix this?

I’m going to assume that that part might be a bug as of right now, but i’m not certain.

Is everything right here fine?

while true do Wait(Timer) 
	wait()
	local Time = 1634900000 - Tick()
	local Days = MF((Time / 60 / 60 / 30) % (250 + 0.250)) 
	local Hours = MF((Time / 60 / 60) % 30) 
	local Minutes = MF((Time / 60) % 60) 
	local Seconds = MF(Time % 60) 

I have the same thing there, but for local Timer = -1 you should try doing

local Timer = 1

Oh. Someone who I was talking to told me to do -1

I haven’t tried what -1 does, it might do the same but yet again I have no idea.

Yea it does the same thing, same with any other number I think. But yea it seems to be exactly 4 Hours, and 1 second behind on what it says inside Studio.

You might want to use os.time instead of tick as tick is relative to the client’s timezone while os.time is fixed to UTC timezone

1 Like

Like this?

wait()

local MF = math.floor
local Next = next 
local Tick = tick 
local Wait = wait
local Stop = 0
local Timer = -1

while true do Wait(Timer) 
wait()
local Time = 1634961600 - os.time()
local Days = MF((Time / 60 / 60 / 30) % (250 + 0.250)) 
local Hours = MF((Time / 60 / 60) % 30) 
local Minutes = MF((Time / 60) % 60) 
local Seconds = MF(Time % 60) 

if Stop == 0 then

	script.Parent.Time.Text = Days..":"..Hours.. ":"..Minutes..":"..Seconds.." "
end

if Days==0 and Hours==0 and Minutes==0 and Seconds==0 or Time < 0 then
Stop=0
script.Parent.Time.Text = "Rejoin!"
	end
end 

Ayy, thank you! It worked, I didn’t know os.time was for that. I really do appreciate it!

1 Like

try enabling API services in studio beta, that always helps transfer data from the game to studio for me.

That wasn’t the issue, I changed the Tick to os.time and it fixed it!