local Players = game:GetService("Players")
local cache = {}
function getUsernameFromUserId(userId)
print("Getting username..")
-- First, check if the cache contains the name
if cache[userId] then return cache[userId] end
-- Second, check if the user is already connected to the server
local player = Players:GetPlayerByUserId(userId)
if player then
cache[userId] = player.Name
return player.Name
end
-- If all else fails, send a request
local name
pcall(function ()
name = Players:GetNameFromUserIdAsync(userId)
end)
cache[userId] = name
print("Got username.")
return name
end
-------------------------------------------------------------------
local leaderboard = game.Workspace:WaitForChild("Leader"):WaitForChild("SurfaceGui"):WaitForChild("Frame1")
local DataStoreService = game:GetService("DataStoreService")
local PointsODS = DataStoreService:GetOrderedDataStore("visits1")
local num = 0
function update()
num=num+1
print("Updating... ["..num.."]")
local isAscending = false
local pageSize = 10
local pages = PointsODS:GetSortedAsync(isAscending, pageSize)
local topTen = pages:GetCurrentPage()
local i = -1
local leaderS=leaderboard:GetChildren()
for v=1, #leaderS do
leaderS[v]:Remove()
end
for rank, data in ipairs(topTen) do
local name = data.key
i=i+1
local points = data.value
local clone = game.Lighting:WaitForChild("sample"):Clone()
clone.points.Text = points
clone.user.Text = getUsernameFromUserId(name)
clone.Position = UDim2.new(0,0,0,i*100)
clone.Parent = leaderboard
end
end
while true do
update()
wait(10)
end
Nothing on the leaderboard. If I search up my name on the Datastore editor, I get 7 (Correct value) so why doesn't this work??
