Speed Run Leaderboard

I would love to implement a leaderboard into my lobby with every users fastest time completing my whole parkour map… just don’t know how to script it or where to start…

what I’m thinking is a part on level 1 that starts a timer, going + and then a part at the end of map that stops timer… that part seems tricky but I think I could tackle it… I just don’t understand how Its possible to track it on a leaderboard part like “Fastest Players All Time”

can someone tell me where I could start or if this even is feasible.

4 Likes

use tick() when they start the map, then measure their progress

local startTime = tick()
--wait for them to finish or something, once finished, put another tick()
local endTime = tick() - startTime

endTime is how long it took

3 Likes

thanks! would you know how to attach it to a part GUI? or is that more advanced

1 Like

If I’m understanding you correctly, this is very simplisitic. Just assign the Text property of your TextLabel:

textLabel.Text = tostring(endTime);

endTime is a number henceforth it must be tostring’d so it can be used for the Text property.


If you’re wanting to save all time records, you should use an OrderedDatastore and save their endTime under their UserId as the key.

When displaying the leaderboard, use GetSortedAsync and use the first DataStorePage. There’s methods under the Players service for getting their username / thumbnail from their UserId if that is needed.

3 Likes

this is exactly what I’m looking for! I’m glad you labeled as simple cause I thought this was going to be difficult. thanks for writing out steps I should take. BIG thanks!

2 Likes

how would I set this up to get this onto a part… I tried some things but nothing was working… should I just set this up in a starter GUI to make a visible timer as well??

1 Like

if you want it to finish when you touch a part, you might need a debounce so it doesn’t bug the GUI


local debounce = false
local gui = (GUIPATH)
local textlabel = gui.Text
local endpart = (PART TO BE TOUCHED PATH)
local startpart = (START PART TO BE TOUCHED PATH)
local startTime
local endTime

startpart.Touched:Connect(function(person)
    if person:IsA("Part") and person.Parent:FindFirstChild("Humanoid") and game.Players:GetPlayerFromCharacter(person.Parent) and not debounce then --checks if it is a player
debounce = true
       startTime = tick()
wait(cooldown)
debounce = false
    end
end)
endpart.Touched:Connect(function(person)
    if person:IsA("Part") and person.Parent:FindFirstChild("Humanoid") and game.Players:GetPlayerFromCharacter(person.Parent) and not debounce then
debounce = true
       endTime = tick() - startTime
           textlabel.Text = tostring(endTime)
wait(cooldown)
debounce = false
    end
end)
1 Like

where do I put this? in a GUI or in the part. so confused, thanks for writing this code out though!

you can either put it in
StarterGui
StarterPlayerScripts
MAKE IT A LOCAL SCRIPT!!!
also np! it would rlly help if you marked solution!

1 Like

would love to mark as solution but I’m not following, after testing around with this script I can’t get it to do anything… just putting this inside StarterGui or inside a frame with text transform the text into 00:00 I am confused more so than when I started lol

the endTime variable will find your race time in seconds, just use this quick function to convert it

local function Convert(seconds)
  local sec = tonumber(seconds)
  return math.floor(sec/60..”:”..(ms%60)
end

That will return a string value to put into minutes and seconds!

1 Like

Hello I have tryed the time code and it’s good,
Almost what I am looking for.
How would you make the stopwatch display the current elapsed time
Until it stops at the finish
Would end Time have to be stored as a
number. Value to use it in a global leaderboard for datastore

Any help would be appreciated I have been trying to solve this for a week
Cheers