Is there a way to make last online tracking system for my admin in my game? So we get last online based on the time they leave the game and time now right? How to get it? And how to convert it to strings + numbers like 20 minutes ago, an hour ago, 2 hours ago.
I think even if need to use DataStore it will not reach limit??? Because my admin is only like 10-15 people so it’s not a lot of people. But how to do itV thank you.
You’d add the player ID to the datastore as true or false, true when they join the game (online) and false when they go offline, if false, log the date.
Yes but how to get differences and make it proper like if it’s only minutes it will only says 2 minutes ago, 3 minutes ago etc but if its already be more than 59 minutes it’s gonna be “an hour ago” then if it’s more or equal to two hours is gonna be like 2 hours ago, 3 hours ago. Then if it change to days is gonna be a day ago, 2 days ago, 3 days ago.
So, first, when one of your admins leaves the game, quickly save the current os.time()
inside a DataStore with the key being their UserId
.
Now each time you wanna see when they’ve been last online, get the Data we saved, do os.time() - {SavedTime}
, it should return the number of seconds since that admin has been last online.
As I see, you want to format that time, you can use this simple function to do it:
function Format(Int)
return string.format("%02i", Int)
end
function convertToHMS(Seconds)
local Minutes = (Seconds - Seconds%60)/60
Seconds = Seconds - Minutes*60
local Hours = (Minutes - Minutes%60)/60
Minutes = Minutes - Hours*60
local FinalString
if Format(Hours) == "0" and Format(Minutes) == "0" then
FinalString = Format(Seconds).." seconds ago"
elseif Format(Hours) == "0" and Format(Minutes) ~= "0" then
FinalString = Format(Minutes).." minutes, "..Format(Seconds).." seconds ago"
elseif Format(Hours) ~= "0" then
FinalString = Format(Hours).." hours, "..Format(Minutes).." minutes and "..Format(Seconds).." seconds ago"
end
return FinalString
end
Examples of how it will look:
{Admin} was last online 39 seconds ago.
{Admin} was last online 5 minutes and 39 seconds ago.
{Admin} was last online 24 hours, 5 minutes and 39 seconds ago.
But can we make not like that, but more like if it’s just minutes it will only show “1 minute ago, 2 minutes ago” etc, and if they already leave an hour or more it will make it “1 hour ago”, “2 hour ago”
Hey! I updated the initial post, now it should display the time how you wanted. Let me know if you have any other questions or issues related to this.
SavedTime = os time on PlayerRemoving right? So os time - savedTime = time now - player removing time right?
If you want to do this I would use adonis admin. It has a command called :leavelogs and shows the time the player left.
yep! thats what it was supposed to mean.