I’m currently trying to set up a system to check how long it has been since the Player last joined the game. The output returns negative numbers, and I was wondering how to correctly figure out the number.
local Login_time = os.time()
local TimeSinceLastSession = Data.LastLogged - Login_time -- Getting the number of seconds between the sessions
local Minutes = TimeSinceLastSession/60
local Hours = Minutes/60
local Days = Hours/24
print(Days..":"..Hours..":"..Minutes)
Data.LastLogged is just the os.time() from when Player left the game.
Output:
You need to subtract the Login_time
from the Last Logged in time. You have it reversed.
Fixed:
local Login_time = os.time()
local TimeSinceLastSession = Login_time - Data.LastLogged -- Getting the number of seconds between the sessions
local Minutes = TimeSinceLastSession/60
local Hours = Minutes/60
local Days = Hours/24
print(Days..":"..Hours..":"..Minutes)
Thank you! I can’t believe the solution was this simple.
No problem. Anyways if you need the explanation:
os.time()
returns the current time in seconds from the Unix Epoch, so this time will always be greater than the last time you called os.time()
. Let’s say your Data.LastLogged
time was 74340
(random number lol), now when you join the next time it’s 79823
, the amount of time between will be the current time subtracted by the last time.