My leaderboard for showing the top 10 players globally is only displaying the first place player in a server. I want it to be global, as well as actually display the top 10 players… Not just first.
When my friend who has more points than I did joined my game, his stat replaced my own placement on the leaderboard, and mine completely vanished- didn’t bump down to #2, just disappeared.
What’s up with this?
for i = 1,10 do
local Ex = script.Example:Clone()
Ex.Name = 1
Ex.Parent = script.Parent.SurfaceGui.Frame.ScrollingFrame
Ex.Pos.Text = " ".. tostring(i)
Ex.Points.Text = ""
Ex.UN.Text = ""
Ex.LayoutOrder = i
script.Parent.SurfaceGui.Frame.ScrollingFrame.CanvasSize = UDim2.new(0,0,0,50*i)
end
function UpdateGui()
for i,v in pairs(game.Players:GetChildren()) do
local DataStore = game:GetService("DataStoreService"):GetOrderedDataStore("PointsManager")
local Data = tonumber(v.leaderstats.Points.Value)
DataStore:SetAsync(v.UserId, Data)
end
local DataStore = game:GetService("DataStoreService"):GetOrderedDataStore("PointsManager")
local Pages = DataStore:GetSortedAsync(false, 10)
local Data = Pages:GetCurrentPage()
for k,v in pairs(Data) do
if tonumber(v.key) >= 1 then
local Frame = script.Parent.SurfaceGui.Frame.ScrollingFrame:FindFirstChild(tostring(k))
if Frame then
Frame.UN.Text = game.Players:GetNameFromUserIdAsync(v.key)
Frame.Points.Text = tostring(v.value)
end
end
end
end
while true do
UpdateGui()
print("updating leaderboard...")
wait(60)
end
Including script examples with your explanations would be awesome, I learn best by example!
local DataStore = game:GetService("DataStoreService"):GetOrderedDataStore("PointsManager")
local Pages = DataStore:GetSortedAsync(false, 10)
local Data = Pages:GetCurrentPage()
for k,v in pairs(Data) do
if tonumber(v.key) >= 1 then
local Frame = script.Parent.SurfaceGui.Frame.ScrollingFrame:FindFirstChild(tostring(k))
if Frame then
Frame.UN.Text = game.Players:GetNameFromUserIdAsync(v.key)
Frame.Points.Text = tostring(v.value)
end
end
end
The code was not displaying the top 10 players globally, only the first place player in each server.
To fix this, the code can be modified to display the top 10 players globally, as well as actually display the top 10 players.
Here is an example of the modified code:
for i = 1,10 do
local Ex = script.Example:Clone()
Ex.Name = 1
Ex.Parent = script.Parent.SurfaceGui.Frame.ScrollingFrame
Ex.Pos.Text = " ".. tostring(i)
Ex.Points.Text = ""
Ex.UN.Text = ""
Ex.LayoutOrder = i
script.Parent.SurfaceGui.Frame.ScrollingFrame.CanvasSize = UDim2.new(0,0,0,50*i)
end
function UpdateGui()
for i,v in pairs(game.Players:GetChildren()) do
local DataStore = game:GetService("DataStoreService"):GetOrderedDataStore("PointsManager")
local Data = tonumber(v.leaderstats.Points.Value)
DataStore:SetAsync(v.UserId, Data)
end
local DataStore = game:GetService("DataStoreService"):GetOrderedDataStore("PointsManager")
local Pages = DataStore:GetSortedAsync(false, 10)
local Data = Pages:GetCurrentPage()
for k,v in pairs(Data) do
if tonumber(v.key) >= 1 then
local Frame = script.Parent.SurfaceGui.Frame.ScrollingFrame:FindFirstChild(tostring(k))
if Frame then
Frame.UN.Text = game.Players:GetNameFromUserIdAsync(v.key)
Frame.Points.Text = tostring(v.value)
end
end
end
end
while true do
UpdateGui()
print("updating leaderboard...")
wait(60)
end
local DataStore = game:GetService("DataStoreService"):GetOrderedDataStore("PointsManager")
local Pages = DataStore:GetSortedAsync(false, 10)
local Data = Pages:GetCurrentPage()
for k,v in pairs(Data) do
if tonumber(v.key) >= 1 then
local Frame = script.Parent.SurfaceGui.Frame.ScrollingFrame:FindFirstChild(tostring(k))
if Frame then
Frame.UN.Text = game.Players:GetNameFromUserIdAsync(v.key)
Frame.Points.Text = tostring(v.value)
end
end
end
Both of these problems might be caused if you are the only one who has joined the game after the leaderboard was created. It might only be showing up with your current server because that is the only server, and the #1 place only shows because there are no other players.
If you did have another player and they were in a different server then I don’t know how to fix the first problem but the second problem might be because the UIs are overlapping, showing the #1 first because (I’m assuming) is the first one to load.
Another possible cause to the second problem is that all the UIs are trying to load at the same time but I don’t think this is it.
Me being the only player on a server isn’t the problem. There should be at least 2 names on the leaderboard, if we’re going for people who joined after the leaderboard was made.
It’s not an overlapping issue because the other UIs load in order.
Here it is in-game.
The numbers being lined up properly shows the UIs aren’t overlapping, but are lined up how they should be. When I put in text for placeholders, this happens too.