Hi, i wanted to make like leaderboard Ui that shows your stats by categories (“Top Doors”, “Top Time”) so there is screenshot of “template”:
so, in conclusion it should shows your data by dataType (doors or time top, when u click either),
this it showcase just for example to understand DataStoreService and how it works for real, so like when i join to the game, i press tp button it teleports me into a “new place” here i get “data info” and tp back into main game (this one), and it shows update/save data, at the start it shows setted info “top doors” ("doors), if i cliked time/doors, it would show this data, so there are scripts:
SERVER MAIN GAME DATA SCRIPT:
local DataStoreService = game:GetService("DataStoreService")
local ts = game:GetService("TeleportService")
local players = game:GetService("Players")
local event = game:GetService("ReplicatedStorage"):FindFirstChild("event")
local doorsStore = DataStoreService:GetOrderedDataStore("Doors_DataStore")
local timeStore = DataStoreService:GetOrderedDataStore("Time_DataStore")
local function updateDataForPlayer(player)
local success, topDoorsPages = pcall(function() return doorsStore:GetSortedAsync(false, 100) end)
local success2, topTimePages = pcall(function() return timeStore:GetSortedAsync(false, 100) end)
if success and success2 then
local doorsReadyData = {}
local timeReadyData = {}
for rank, entry in pairs(topDoorsPages:GetCurrentPage()) do
local username = pcall(function() return players:GetNameFromUserIdAsync(entry.key) end)
if username then
table.insert(doorsReadyData, {
rankIndex = rank,
playerUsername = username,
dataValue = entry.value
})
end
end
for rank, entry in pairs(topTimePages:GetCurrentPage()) do
local username = pcall(function() return players:GetNameFromUserIdAsync(entry.key) end)
if username then
table.insert(timeReadyData, {
rankIndex = rank,
playerUsername = username,
dataValue = entry.value
})
end
end
return doorsReadyData, timeReadyData
end
end
game.Players.PlayerAdded:Connect(function(player)
local joinData = player:GetJoinData()
local tpData = joinData.TeleportData
if tpData then
pcall(function()
doorsStore:UpdateAsync(tostring(player.UserId), function(oldValue)
local new = tpData.doorPassed or 0
return math.max(oldValue or 0, new)
end)
end)
pcall(function()
timeStore:UpdateAsync(tostring(player.UserId), function(oldValue)
local new = tpData.imeSpent or 0
return math.max(oldValue or 0, new)
end)
end)
task.wait(1)
local doors, times = updateDataForPlayer(player)
event:FireClient(doors, times)
end
end)
CLIENT MAIN GAME SCRIPT: (for updating/showing data)
local players = game:GetService("Players")
local event = game:GetService("ReplicatedStorage"):FindFirstChild("event")
local screenGui = players.LocalPlayer.PlayerGui:WaitForChild("ScreenGui")
local scrollingFrame = screenGui.LeaderboardFrame.ScrollingFrame
local template = scrollingFrame:WaitForChild("PlayersData")
template.Visible = false
local currentTopDoorData = {}
local currentTopTimeData = {}
local currentCheck = "doors"
local function formattedTime(seconds: number)
return string.format("%02d:%02d", math.floor(seconds / 60), seconds % 60)
end
local function cleanData()
for _, frame in ipairs(scrollingFrame:GetChildren()) do
if frame:IsA("Frame") and frame ~= template then
frame:Destroy()
end
end
end
local function timeCounting()
for i = 60, 0, -1 do
screenGui.LeaderboardFrame.countingTime.Text = formattedTime(i)
task.wait(1)
end
end
local function showPlayerData(dataType)
cleanData()
for _, data in ipairs(dataType) do
local newDataFrame = template:Clone()
newDataFrame.Parent = scrollingFrame
newDataFrame.Visible = true
newDataFrame.NumberValue.Text = data.rankIndex
newDataFrame.PlayerNameLabel.Text = data.playerUsername or "Unknown"
if currentCheck == "time" then
newDataFrame.ValueLabel.Text = formattedTime(data.dataValue)
else
newDataFrame.ValueLabel.Text = tostring(data.dataValue)
end
end
end
for _, button in ipairs(screenGui.LeaderboardFrame:GetChildren()) do
if button:IsA("TextButton") then
button.MouseButton1Click:Connect(function()
currentCheck = (button.Name == "doorbut") and "doors" or "time"
showPlayerData(currentCheck == "doorbut" and currentTopDoorData or currentTopTimeData)
end)
end
end
event.OnClientEvent:Connect(function(doorData, timeData)
currentTopDoorData = doorData
currentTopTimeData = timeData
showPlayerData(currentCheck == "doors" and currentTopDoorData or currentTopTimeData)
end)
task.spawn(function()
while true do
showPlayerData(currentTopDoorData)
timeCounting()
end
end)
MAIN TELEPORT SERVER SCRIPT:
local ts = game:GetService("TeleportService")
local tpSignal = game:GetService("ReplicatedStorage"):FindFirstChild("tpSignal")
tpSignal.OnServerEvent:Connect(function(player)
local success, err = pcall(function()
return ts:TeleportAsync(96170397388301, {player})
end)
end)
PLACE TELEPORT SERVER SCRIPT:
local ts = game:GetService("TeleportService")
local tpSignal = game:GetService("ReplicatedStorage"):FindFirstChild("tpSignal")
tpSignal.OnServerEvent:Connect(function(player, doorsPassed, timeSpent)
local tpOptions = Instance.new("TeleportOptions")
tpOptions:SetTeleportData({
doorsPassed = doorsPassed,
timeSpent = timeSpent
})
local success, err = pcall(function()
return ts:TeleportAsync(112647346320080, {player}, tpOptions)
end)
end)
PLACE CLIENT SCRIPT:
local players = game:GetService("Players")
local ts = game:GetService("TeleportService")
local tpSignal = game:GetService("ReplicatedStorage"):FindFirstChild("tpSignal")
local screenGui = players.LocalPlayer.PlayerGui:WaitForChild("ScreenGui")
local doorsPassed = 5
local timeSpent = 150
screenGui.TextButton.MouseButton1Click:Connect(function()
tpSignal:FireServer(players.LocalPlayer, doorsPassed, timeSpent)
end)
i hope someone can help me with it, it;s so complesx for my mind enough and i spent time watching tutorials (to get smth new), read documentation and even used ai to check if i’m go in correct way.. seems no
(*srry for my english if it’s bad, it’s not my native language.)












