Detecting after 3 hours has gone by (OS.TIME ASSISTANCE)


Hello. I am assisting on game (as an developer) and I’m adding a little obby you have to beat with 3 attempts, if you lose all attempts, you will have to wait 3 hours for a restock, however I am very new to the os.time section, so when I lose all of my lives, I save up a value of when they died, but how would I detect when 3 hours has gone by?

You have to find the difference between the current time and the time the player lost all the three attempts

In this example, take loseTime as the os.time() that was recorded during the time the player lost all of their attempts

if os.time() - loseTime >= 10800 then -- 10800 = 3 hours
    --the time has passed
    --remove the datastore record from the player & let them try again
1 Like

By the way, how do you detect the amount of time in numbers like u did

You can use a calculator or straight up just google it

You can memorize the following

1 minute = 60 seconds (60 seconds)
1 hour = 60 minutes (60*60 = 3600 seconds)
1 day = 24 hours (24*60*60 = 86400 seconds)

To get an hour of seconds you’d multiply 60 by 60
To get a day of seconds you’d multiply 3600 seconds (60*60) by 24
To get a week you’d multiply a day by 7, etc…

1 Like

Thank you so much! This is so helpful!