Global Leaderboard for time?

  1. What do you want to achieve?

a global leaderboard that tracks how fast a player completed a map…

I already have a timer with a working GUI thanks to @luya_yobanka in post below

was setting up a clone of the global leaderboard simple set up from this post

which was a lot of help getting the UI together but i’m stuck now because his and many others I’ve googled base their globals on coins, points, etc but I’d like to track a time.

would anyone know the proper way to set this up please?

can donate some bux

2 Likes

You’d want to setup a ordereddatastore, that stores people’s times.

After that’s done when loading the UI list you’d want to do do getsortedasync to get the top x amount of people

2 Likes

I followed the simple global and they also set up a ordereddatastore, I pretty much have first bit of script down I just don’t understand how to get player times

1 Like

Not sure how your race works, but uh when the race starts for a player get the tick() then do tick() - starttime to get the completion time

then :UpdateAsync it to the leaderboard or well setasync first if they dont have data I think

1 Like

If you have a system for tracking how fast someone completed a course. Then all you would have to use is :SetAsync() into your OrderedDataStore. So how it would work is once the player completes the race, you’d insert their time into the DataStore. Example:

local Store = game:GetService("DataStoreService"):GetOrderedDataStore("StoreName")

local function raceFinished(player, time)
    local key = player.UserId
    local success, err = pcall(function()
        Store:SetAsync(key, time)
    end)
    if not success then warn(err) else
        return print("Saved time for, ".. player.Name)
    end
end

Then in your leaderboard script you could run another pcall function using :GetNameFromUserIdAsync() to get the player’s name since the key is their userId which never changes (to my knowledge). Then compare using your Order Data Stores, :GetSortedAsync() function and do your leaderboard stuff.

2 Likes

I don’t have a system for getting the players info saved. I just don’t get what leaderboard scripting is like though… is there a tutorial I can follow for it? cause I’ve looked and most all globals are not based on time. would I just need to change from say ‘cash’ to ‘time’

As long as you have the value stored somewhere, you can put it on a leaderboard. That’s how coins, points, and other currency can be stored. Time is just a number.

For my specific leaderboard, you can either modify where the value is pulled from and saved:

or, you can save to the same ordered data store and the leaderboard will use the saved data. (If you do this make sure to remove the saving part)

I don’t see where I would edit from coins to time though, in the script you posted
local w = plr.leaderstats.Cash.Value

but I don’t have a leaderstats that track the time, its just a screengui at bottom of screen away from leaderstats.

To store data, it has to be on the server. The client can’t store it’s own data. You could use RemoteEvents to send this value to the server, but this has security risks. Ideally, you should have the data being tracked on the server for security purposes. If the client needs it, you can either use value objects or RemoteEvents to send it to them.

1 Like

how else beside remote events would I be able to sent the time value to the server?

There is no way to send information to the server from a client without using RemoteEvents or RemoteFunctions. RemoteEvents and RemoteFunctions exist solely for client-server and server-client communication.

Any other way that works is most likely not intended behavior and not a great idea to use. Is there a reason you wish not to use remote events?

yes “You could use RemoteEvents to send this value to the server, but this has security risks”
I don’t like security risks

The security risk isn’t that data is being sent; It’s that the data is being determined by the client in the first place.

The server should be tracking the data so an exploiter cant just say they have 90000000000.

Hello @CrillicD, just wondering if you have managed to get your script working, as me and my son are needing a similar script. We have a working timer in leaderstats and would like to know how to register the time on a global leaderboard when a certain block is touched. We have set up an ordered data store but it is not registering the time. Thank you.