How can i make Countdown system with os.time()?

Hello! I made a data-saving system for my game, and it’s working perfect; it saves players’ inventory, points, etc., but I want to do more.
like this:

If the player leaves the game with saved data, it will countdown with os.time(). I also added loading data with the clicking button system, so if you click that the countdown will be paused. If the player is not going to load their data or is not going to join the game, and if the countdown ends, the player’s data will be deleted so I want to do a temporary data system with this countdown system. But i don’t know how can i do this i never used “os.time(), os.clock(), os.date()” before.

Button Load Data system:
screenshot

I’ll show you how you can use os.time():

local currentTime = os.time();
task.wait(3);
print(os.time() - currentTime); -- this will print '3' as 3 seconds passed

What you can do is store an os.time() value on the player’s data, and the next time they join check if it’s higher than X seconds and if so, delete their data. For example, if you wanted to check if 12 hours passed, you’d check:

os.time() - dataTime >= 43200

dataTime being the value you saved in the player’s data.

1 Like

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