I am trying to create a leader board that shows how long a user has played the game globally. Is there any scripts that can help create this? I do not want to create a leader board for how long someones been in the server. I am having trouble creating a script like this since there is no tutorials. Most leader board scripts are for wins, KO’s, etc.
This is a example of a model I found but has no script for it:
No I don’t but you could always just make a table/object to store the value of how long the player has spent on your game. It’s value could go up every second.
All you need to do is track how long the player has been in the server, and update the script to reflect this change. This would require a separate script that would increment the Wins intValue (you’ll probably rename this to “TimeSpent” or something) in each player’s leaderstats folder. Something like…
while wait(1) do
for _, player in pairs(game.Players:GetPlayers()) do
local leaderstats = player:FindFirstChild("leaderstats")
local TimeSpent = leaderstats:FindFirstChild("TimeSpent")
if TimeSpent then
TimeSpent.Value = TimeSpent.Value + 1
end
end
end
…might work out. Then, you would change it so that the Ordered Datastore will update with the time spent.
Make sure to change the first script which initializes the player’s leaderstats folder and subsequent intValue so that the name of the intValue in the folder is “TimeSpent” or whatever you want to name it instead of “Wins.” However, I recommend not using ObjectValues and instead create a table, but the above method is the simplest protocol for your request.