Timer gui not working properly?

(I dont know if I am just being dumb or what. I have searched around and not found any fixes.)

Hey, for some reason my countdown timer will randomly go from 29 days to 1 day to 20 seconds?

What am I doing wrong here?

local enddate = 1587775270
while require(game.ReplicatedStorage.Modules.WaitControl).Wait(1) do
	local between = enddate-game.ReplicatedStorage.Events.PremiumEvents.GetTime:InvokeServer()
	local days = math.floor(between/86400)
	between = between - (days*86400)
	local hours = math.floor(between/3600)
	between = between - (hours*3600)
	local mins = math.floor(between/60)
	between = between - (mins*60)
	local seconds = between
	if string.len(tostring(days)) == 1 then
		days = "0"..days
	else
		days = tostring(hours)
	end
	if string.len(tostring(hours)) == 1 then
		hours = "0"..hours
	else
		hours = tostring(hours)
	end
	if string.len(tostring(mins)) == 1 then
		mins = "0"..mins
	else
		mins = tostring(mins)
	end
	if string.len(tostring(seconds)) == 1 then
		seconds = "0"..seconds
	else
		seconds = tostring(seconds)
	end
	script.Parent.Text = days..":"..hours..":"..mins..":"..seconds
end
1 Like

You can start fixing the bug by using print() to determine why the value is fluctuating so much.

Can you try printing out the time value held in the server, and see if that reads normally? it is possible this gui display is working fine, and it is the timer that is broken.

Can we see what the code behind the RemoteEvent does?

The code simply returns the os.time() and that is it.

1 Like
if string.len(tostring(days)) == 1 then

Why are you using ==? The >= should be better for this situation. Also, you could just use this:

if days >= 1 then

If I did what you suggest, if for example the day value was 24 using that code would make it end up like 024:

The reason I have that code is to make it so that for example 4 days becomes 04 days.

1 Like

You can try print(days, between) to make sure the numbers are being counted correctly.