Os.time data storing

So I was making a daily reward chest but the only thing I am stuck on is making the timer on the BillboardGui. It wouldn’t save when the player left. When the player had one hour left until the chest came back, they would rejoin and it would say 23:59.

And I also need to know how to take some of the time away when the player is offline. For example, if a player is not on the game for 2 hours after the chest was claimed, it would say 22:00 when they rejoin.

os.time() will return a timestamp - this is the value you want to save. You can see how much time has passed since that timestamp by creating a new one and subtracting:

local startTime = os.time()
-- ..some time may pass here...
local deltaTime = os.time() - startTime
if deltaTime > 60*60*24 then
    -- At least one day has passed!
end

Sorry, I skimmed the question and gave a potentially not relevant answer. Perhaps you’re looking to format the amount of seconds remaining into a properly formatted time. This just involves some division and modulo operations:

local savedTime = -- The time you saved when they last claimed the reward
local timeLeft = os.time() - savedTime
-- Do some division, modulo and rounding to get the values you need:
local hours = math.floor(timeLeft / (60*60))
local minutes = math.floor(timeLeft % (60*60) / 60)
-- string.format with %02d will display a digit 2-columns wide with leading zeros:
print(("%d:%02d"):format(hours, minutes))
1 Like