How would I log play time?

I would like a system of logging play times to a spreadsheet, discord, or whatever it could be. Is there any way to do this?

2 Likes

Pretty sure this would be unnecessary as Roblox already has a feature for place statistics.

2 Likes

Yes, but I want specific users, as I am looking to pay my moderators hourly, and also make a leaderboard of the most time played

1 Like

Just create a normal datastore and add onto the value every second or so (don’t use wait(), not a good idea, tick/os.time/etc I forgot is a better idea).

And save when they leave instead of saving every single time since that will reach limits very quickly if u do.

:+1:

Though as @EquivocalCrow, I believe it’s unneccessary to have to log players play time.

5 Likes

get time elapsed like this :

local t = tick() -- when the player joins, Players.PlayerAdded
wait(3) --// or whenever the player leaves, Players.PlayerRemoving

local elapsed = tick() - t 
print(elapsed)
1 Like

Would I use this with a data store?

1 Like

if you want, save the time . Maybe add it to the previous time played each time and when the player leaves, save the combined Time Played and save that.

2 Likes

How would I save the time? Are there logs?

1 Like

with my example you would just same the time played as a number value.

edit : since you are making this yourself, you would create your own value for each player , alter the value there and save that value to the DataStore as well. There is no other way to log time that I know of.

1 Like

Ah, I see. Where would I find this value?

1 Like

Please search before posting threads, there’s already threads about doing this around here.

os.time when they join, os.time when they leave. Cache the join os.time in a dictionary, get the difference between that and the os.time when they leave, that’s how long they were in the server for. Save that using a DataStore. You’re set.

local JOIN_TIMES = {}

PlayerAdded(plr)
    JOIN_TIMES[plr] = os.time

PlayerRemoving
    currentTime = os.time
    joinTime = JOIN_TIMES[plr]
    difference = currentTime - joinTime
    DataStore:SetAsync(userId, difference)
5 Likes