How could you make a board that logs the amount of time people play for, for example if someone plays for 3 hours it logs it and on a board there is a leader board saying who has played for the longest amount of time.
Thanks,
George
2 Likes
Please search before posting threads. Some threads I found on this topic that I found in 5 seconds from the DevForum search bar alone:
Things like this are done through OrderedDataStores. A reminder that you should generally try things out yourself before posting threads: this is not a do-my-work category.
When a player joins, you log the current time from os.time preferably in a dictionary. When they leave, you will also grab the current time but subtract the time they joined from this new value to get how long they were on. From here, you can call IncrementAsync on the player’s UserId for the key and that difference of time …
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 = curren…
Generally, for what you’re looking for, doing tick() when the player joins and store it in a table suffices, but seen as to how you don’t want to keep seconds, but rather just the minutes (so that the player must redo the minute as you stated), you can do a slight tweaking on the final tick() - start subtraction.
To keep just the minutes and no second, but also not increase the minute when it shouldn’t be, you can resort to modulus.
I know you know what modulus is, but since some users don’t …
I know I saw those but I do not understand how I could make it work-
1 Like