Os.time() confusion

Making a chest that is claimed every 6 hours, server side works fine but I can’t make it show the remaining time. Here’s the code:

	local Time = newDataValue.Inventory.Chests["Energy Orbs Chest #1"];
	local secondsRemaining = os.time() - (Time - 21600);
	local TimeLeft = "READY"
	if secondsRemaining <= 0 then
		TimeLeft = "READY";
	else
		TimeLeft = string.format("%02i:%02i:%02i", (secondsRemaining * 60 * 60) % 24, (secondsRemaining * 60) % 60, secondsRemaining % 60)
	end

Any ideas?

How frequently is this code running?

It looks like the math in your format string is a bit off. Try this:

TimeLeft = string.format("%02i:%02i:%02i", secondsRemaining / 3600, (secondsRemaining / 60) % 60, secondsRemaining % 60)

Ty! There’s 1 other issue where it’s just counting up instead? I believe it’s the secondsRemaining variable this time!

Runs about every 0.5-1 seconds.

Solved! This is the new secondsRemaining line:

local secondsRemaining = 21600 - (os.time() - Time)

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