How to make a Global Most played time Leaderboard?

Hi Developers! I’m here today because I need a leaderboard for my game it’s a global most played time Leaderboard but I don’t know how to script so I need help but sadly if you guys want to get paid just for this this isn’t the post for you because I ran out of funds so I can’t pay you guys. But it’s okay if you guys don’t help me for robux.i just need the scripts and tell me in where I should put it.thank you for reading this


If you’re using the default leaderboard you could take a look at using leaderstats and the DataStoreService.

Hmmm what default leaderboard? I know leaderstats it’s like a leaderboard but it’s in your tab but idk DataStoreService

image - Default leaderboard (with leaderstats)

DataStoreService allows you to save user data so it can be loaded on other game instances or when they rejoin

I want a leaderboard tho so anyone can see it and mobile players can see it too because I can’t find anything in youtube

If you’ve not made a custom one the default one will do just fine. I was mostly checking so I didn’t give you the wrong advice

Ok thanks for the leaderboard but the problem is I need a script to make it happen but idk anything in how to script can you help me with that?

If you take a look at the wiki page on leaderstats they have a sample script that you could likely just copy and paste and then adapt to your needs

Oh ok I’ll check it right now but do I still need the DataStoreService?

You can create a DataStore that save the time that a player has played and then set it on a Label.

If you wish to save the user’s data, yes

Okay guys thanks so much for the help

1 Like

How to record time:
Log when the player is added with a playerAdded event
Create a new value
make a new value, set it to tick()
Now when they exit, the time played is tick() - the value. (in seconds)

local Players = game:GetService("Players")
local DSS = game:GetService("DataStoreService")
local Store = DSS:GetDataStore('TimePlayed')
     local Data 
     if not Store:GetAsync('Player_'..Player.UserId) then
           Store:SetAsync('Player_'..Player.UserId, 0); Data = 0
          Data = Store:GetAsync('Player_'..Player.UserId) 
    local TickSession ="IntValue", Player)
    TickSession.Name = "TickSession"
    TickSession.Value = tick()
    local Value ="IntValue", Player)
    Value.Name = "TimePlayed"
    Value.Value = Data
       local TimePlayed = tick() - Player.TickSession
       pcall(function() Store:SetAsync('Player_'..Player.UserId, Player.TimePlayed.Value + TimePlayed) end)
1 Like

Ok you can use this two tutorials and match them.

TheDevKing - How to make a global leaderboard
Tech with Mike - How to create a leaderstats for time

You can use Tech with Mike’s tutorial to create the time leaderstats and TheDevKing’s tutorial to create the global leaderboard

I’m not sending the scripts because it’s a little bit hard to explain…

Hope to have helped :grinning: