Hello! I have 2 global leaderboards. One for coins and one for wins. Problem: They show the same value.
At first I thought it was nothing to worry about but then I got suspicious.
I used a global leaderboard from the toolbox (I was only using it to test my leaderboard) to see if it was showing the same value and sure enough, both of my leaderboards were showing only wins, not coins.
On the global leaderboard I used from the toolbox, it said:
But on my global leaderboards, they said:
Here are my script in my leaderboards:
Wins:
local sg = script.Parent.Parent.SurfaceGui
local sample = script:WaitForChild("Frame") --Our Sample frame
local sf = sg:WaitForChild("ScrollingFrame") --The scrolling frame
local ui = sf:WaitForChild("UIListLayout") --The UI list layout
local dataStoreService = game:GetService("DataStoreService")
--The data store service
local dataStore = dataStoreService:GetOrderedDataStore("Leaderboard")
--Get the data store with key "Leaderboard"
while true do
for i, v in pairs(game.Players:GetPlayers()) do--Loop through players
if v.UserId>0 then--Prevent errors
local w = v.leaderstats.Wins.Value--Get value
if w then
pcall(function()
--Wrap in a pcall so if Roblox is down, it won't error and break.
dataStore:UpdateAsync(v.UserId, function(oldVal)
--Set new value
return tonumber(w)
end)
end)
end
end
end
local smallestFirst = false--false = 2 before 1, true = 1 before 2
local numberToShow = 50--Any number between 1-100, how many will be shown
local minValue = 1--Any numbers lower than this will be excluded
local maxValue = 10e30--(10^15), any numbers higher than this will be excluded
local pages = dataStore:GetSortedAsync(smallestFirst, numberToShow, minValue, maxValue)
--Get data
local top = pages:GetCurrentPage()--Get the first page
local data = {}--Store new data
for a,b in ipairs(top) do--Loop through data
local userid = b.key--User id
local points = b.value--Points
local username = "[Failed To Load]"--If it fails, we let them know
local s,e = pcall(function()
username = game.Players:GetNameFromUserIdAsync(userid)--Get username
end)
if not s then--Something went wrong
warn("Error getting name for "..userid..". Error: "..e)
end
local image = game.Players:GetUserThumbnailAsync(userid, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size150x150)
--Make a image of them
table.insert(data,{username,points,image})--Put new data in new table
end
ui.Parent = script
sf:ClearAllChildren()--Remove old frames
ui.Parent = sf
for number,d in pairs(data) do--Loop through our new data
local name = d[1]
local val = d[2]
local image = d[3]
local color = Color3.new(1,1,1)--Default color
if number == 1 then
color = Color3.new(1,1,0)--1st place color
elseif number == 2 then
color = Color3.new(0.9,0.9,0.9)--2nd place color
elseif number == 3 then
color = Color3.fromRGB(166, 112, 0)--3rd place color
end
local new = sample:Clone()--Make a clone of the sample frame
new.Name = name--Set name for better recognition and debugging
new.LayoutOrder = number--UIListLayout uses this to sort in the correct order
new.ImageLabel.Image = image--Set the image
new.ImageLabel.BackgroundTransparency = 1
new.ImageLabel:FindFirstChild("Position").Text = number --Set the place
new.ImageLabel:FindFirstChild("Position").TextColor3 = color--Set the place color (Gold = 1st)
new:FindFirstChild("PlayerName").Text = name--Set the username
new:FindFirstChild("Wins").Text = val--Set the amount of points
new:FindFirstChild("Wins").TextColor3 = color--Set the place color (Gold = 1st)
new:FindFirstChild("PlayerName").TextColor3 = color--Set the place color (Gold = 1st)
new.Parent = sf--Parent to scrolling frame
end
wait()
sf.CanvasSize = UDim2.new(0,0,0,ui.AbsoluteContentSize.Y)
--Give enough room for the frames to sit in
wait(10)
end
Coins:
local sg = script.Parent.Parent.SurfaceGui
local sample = script:WaitForChild("Frame") --Our Sample frame
local sf = sg:WaitForChild("ScrollingFrame") --The scrolling frame
local ui = sf:WaitForChild("UIListLayout") --The UI list layout
local dataStoreService = game:GetService("DataStoreService")
--The data store service
local dataStore = dataStoreService:GetOrderedDataStore("Leaderboard")
--Get the data store with key "Leaderboard"
while true do
for i, v in pairs(game.Players:GetPlayers()) do--Loop through players
if v.UserId>0 then--Prevent errors
local w = v.leaderstats.Coins.Value--Get value
if w then
pcall(function()
--Wrap in a pcall so if Roblox is down, it won't error and break.
dataStore:UpdateAsync(v.UserId, function(oldVal)
--Set new value
return tonumber(w)
end)
end)
end
end
end
local smallestFirst = false--false = 2 before 1, true = 1 before 2
local numberToShow = 50--Any number between 1-100, how many will be shown
local minValue = 1--Any numbers lower than this will be excluded
local maxValue = 10e15--(10^15), any numbers higher than this will be excluded
local pages = dataStore:GetSortedAsync(smallestFirst, numberToShow, minValue, maxValue)
--Get data
local top = pages:GetCurrentPage()--Get the first page
local data = {}--Store new data
for a,b in ipairs(top) do--Loop through data
local userid = b.key--User id
local points = b.value--Points
local username = "[Failed To Load]"--If it fails, we let them know
local s,e = pcall(function()
username = game.Players:GetNameFromUserIdAsync(userid)--Get username
end)
if not s then--Something went wrong
warn("Error getting name for "..userid..". Error: "..e)
end
local image = game.Players:GetUserThumbnailAsync(userid, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size150x150)
--Make a image of them
table.insert(data,{username,points,image})--Put new data in new table
end
ui.Parent = script
sf:ClearAllChildren()--Remove old frames
ui.Parent = sf
for number,d in pairs(data) do--Loop through our new data
local name = d[1]
local val = d[2]
local image = d[3]
local color = Color3.new(1,1,1)--Default color
if number == 1 then
color = Color3.new(1,1,0)--1st place color
elseif number == 2 then
color = Color3.new(0.9,0.9,0.9)--2nd place color
elseif number == 3 then
color = Color3.fromRGB(166, 112, 0)--3rd place color
end
local new = sample:Clone()--Make a clone of the sample frame
new.Name = name--Set name for better recognition and debugging
new.LayoutOrder = number--UIListLayout uses this to sort in the correct order
new.ImageLabel.Image = image--Set the image
new.ImageLabel.BackgroundTransparency = 1
new.ImageLabel:FindFirstChild("Position").Text = number --Set the place
new.ImageLabel:FindFirstChild("Position").TextColor3 = color--Set the place color (Gold = 1st)
new:FindFirstChild("PlayerName").Text = name--Set the username
new:FindFirstChild("Wins").Text = val--Set the amount of points
new:FindFirstChild("Wins").TextColor3 = color--Set the place color (Gold = 1st)
new:FindFirstChild("PlayerName").TextColor3 = color--Set the place color (Gold = 1st)
new.Parent = sf--Parent to scrolling frame
end
wait()
sf.CanvasSize = UDim2.new(0,0,0,ui.AbsoluteContentSize.Y)
--Give enough room for the frames to sit in
wait(10)
end
Read it from this topic:
Can you help me fix this issue?