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?
Pretty sure this would be unnecessary as Roblox already has a feature for place statistics.
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
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.
Though as @EquivocalCrow, I believe it’s unneccessary to have to log players play time.
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)
Would I use this with a data store?
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.
How would I save the time? Are there logs?
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.
Ah, I see. Where would I find this value?
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)