How to go about creating a speedrun leaderboard

Hello! I’m here to ask quite a simple question, how would I create a speedrun leaderboard?

To clarify the question, I’m asking how to create a leaderboard where all the values go in a way so the lowest time is at the top, and every time a player finishes a course, it somehow saves the time.

Now, I am really bad at DB’s and anything related to them so doing this + needing to make it go down instead of up is a lot for me.

The code where the player finishes is

    -- Some code up here...
	if d.Name=='Timer_Stop' then
		connectplrtouch(d,function()
			timer_active=false
			timerlabel.TextColor3=Color3.new(0.98822, 0.338933, 0.325734)
			
			game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = game.Workspace.Lobby.DifficultyChart.SpawnLocation.CFrame


			wait(1)
			par.Enabled=false
			timer_time=0
			wait(1.5)
		end)
	end

Which is just an edited version of Jukerise’s timer system. Any help on how to save the time/how to create the lower = better leaderboard would be greatly appreciated!

Well, first, to make a leaderboard, in another script in the serverscriptservice and write in,


function onPlayerEntered(player)

local leaderstats = Instance.new("Model")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player

local bestTimeBoard = Instance.new("IntValue")
bestTimeBoard.Name = "Best Time"
bestTimeBoard.Value = 0
bestTimeBoard.Parent = leaderstats

end

game.players.playeradded:Connect(onPlayerEntered)

This will give you the leaderboard part of it.
More will be explained in the next post.

You could say something like this, when so and so happens

function onPartTouch(part)
   local character = part.Parent
   local humanoid = part.Parent:FindFirstChild("Humanoid ")
   if humanoid then
     local player = game.Players:GetPlayerFromCharacter(character)
     local Time = player.leaderstats["Best Time"]
     if timer_time < Time then
         Time.Value = timer_time
      end
   end
end
script.Parent.Touched:Connect(onPartTouch)

this won’t fit exactly in your code, you will need to modify it a bit to make it work with your code
Note: put this in the part that the player will touch