Confusion with making a time trial leaderboard!

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Making a leaderboard for my obby!
  2. What is the issue? Include screenshots / videos if possible!
    Well I just don’t understand where to put anything inside of the leaderboard script! I’ve already made the leaderboard but I don’t know how to make a serverscriptservice script for it since I’m a beginner! I’ve searched on youtube how to do it and I even asked one of the youtubers who’s video I watched but they got an attitude with me!
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub? Youtube and I made a post for it on the devhub a couple weeks ago!

Below are my 2 scripts that I have right now! They both work flawlessly but I’m having trouble making another script in serverscriptservice that will make the times show up on the time trial leaderboard I’m making for my obby! Also here’s the game if you want to test it! :sunglasses: :100:
Jaylin’s 100 Stage Obby - Roblox

Here is my local TimerGuiScript:

local player = Players.LocalPlayer
local currentTime = player:WaitForChild("CurrentTime")
local personalBest = player:WaitForChild("PersonalBest")
local replicatedStorage = game:GetService("ReplicatedStorage")

local function secondsToMinSecMs(seconds)
	local minutes = math.floor(seconds / 60)
	local remainingSeconds = seconds % 60
	local secondsSplit = math.floor(remainingSeconds)
	local millisecondsSplit = math.floor((remainingSeconds - secondsSplit) * 100)

	return string.format("%02i:%02i.%02i", minutes, secondsSplit, millisecondsSplit)
end

local textLabel = script.Parent
textLabel.Text = "Timer: " .. secondsToMinSecMs(currentTime.Value) .. "\nPersonal Best: " .. secondsToMinSecMs(personalBest.Value)

while true do
	textLabel.Text = "Timer: " .. secondsToMinSecMs(currentTime.Value) .. "\nPersonal Best: " .. secondsToMinSecMs(personalBest.Value)
	task.wait()
end

**Here is my serverscriptservice DataSaverScript:**

local players = game:GetService("Players")

local dataStoreService = game:GetService("DataStoreService")
local dataStore = dataStoreService:GetDataStore("PersonalBest")

local replicatedStorage = game:GetService("ReplicatedStorage")
local bestTime = replicatedStorage:WaitForChild("BestTime")

local function playerAdded(plr)
	local personalBest = Instance.new("NumberValue")
	personalBest.Name = "PersonalBest"
	personalBest.Value = dataStore:GetAsync("Best_" .. plr.UserId) or math.huge
	personalBest.Parent = plr

	local currentTime = Instance.new("NumberValue")
	currentTime.Name = "CurrentTime"
	currentTime.Value = 0
	currentTime.Parent = plr

	local startTime = Instance.new("NumberValue")
	startTime.Name = "StartTime"
	startTime.Value = 0
	startTime.Parent = plr

	local timerStopped = Instance.new("BoolValue")
	timerStopped.Name = "TimerStopped"
	timerStopped.Value = true
	timerStopped.Parent = plr

	personalBest:GetPropertyChangedSignal("Value"):Connect(function()
		personalBest.Value = math.clamp(personalBest.Value, 1/math.huge, math.huge)
	end)

	while true do
		if timerStopped.Value == false then
			currentTime.Value = tick() - startTime.Value
		end
		task.wait()
	end
end

for _, plr in ipairs(players:GetPlayers()) do
	task.spawn(playerAdded, plr)
end

players.PlayerAdded:Connect(playerAdded)

players.PlayerRemoving:Connect(function(plr)
	dataStore:SetAsync("Best_" .. plr.UserId, plr.PersonalBest.Value)
end)

game:BindToClose(function()
	for _, plr in ipairs(players:GetPlayers()) do
		dataStore:SetAsync("Best_" .. plr.UserId, plr.PersonalBest.Value)
	end
end)

local startTimer = workspace.StartTimer
local endTimer = workspace.EndTimer

startTimer.Touched:Connect(function(part)
	local char = part.Parent
	local hum = char:FindFirstChildOfClass("Humanoid")
	local plr = players:GetPlayerFromCharacter(char)

	if char and plr and hum.Health > 0 and plr.TimerStopped.Value == true then
		plr.CurrentTime.Value = 0
		plr.StartTime.Value = tick()
		plr.TimerStopped.Value = false
	end
end)

endTimer.Touched:Connect(function(part)
	local char = part.Parent
	local hum = char:FindFirstChildOfClass("Humanoid")
	local plr = players:GetPlayerFromCharacter(char)

	if char and plr and hum.Health > 0 then
		plr.TimerStopped.Value = true
		if plr.CurrentTime.Value < plr.PersonalBest.Value then
			plr.PersonalBest.Value = plr.CurrentTime.Value
		end
	end
end)

I’ve not made a leaderboard ever, but I think you might run into an issue. The data stores are not ordered.

Typically, ordered data stores are able to be sorted, hence why they’re used in leaderboards.

This might help:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.