Hello,
I am making a global leaderboard for my game that displays the top 50 players with the most "LadderPoints" (player.leaderstats.LadderPoints).
I already have a script, but there is an error on line 41: Attempt to concatenate nil with string. Here is the script (I put the whole thing incase you need to see the rest):
local sg = script.Parent
local sample = script:WaitForChild("Sample")
local sf = sg:WaitForChild("ScrollingFrame")
local ui = sf:WaitForChild("UI")
local dataStoreService = game:GetService("DataStoreService")
local dataStore = dataStoreService:GetOrderedDataStore("LadderData")
wait(5)
while true do
for i, plr in pairs(game.Players:GetChildren()) do
if plr.UserId > 0 then
local w = plr.leaderstats.LadderPoints.Value
if w then
pcall(function()
dataStore:UpdateAsync(plr.UserId,function(oldVal)
return tonumber(w)
end)
end)
end
end
end
local smallestFirst = true
local numberToShow = 50
local minValue = 1
local maxValue = 99999
local pages = dataStore:GetSortedAsync(smallestFirst, numberToShow, minValue, maxValue)
local top = pages:GetCurrentPage()
local data = {}
for a,b in ipairs(top) do
local userid = b.Key
local points = b.Value
local username = "[Failed To Load]"
local s,e = pcall(function()
username = game.Players:GetNameFromUserIdAsync(userid)
end)
if not s then
warn("Error getting name for "..userid..". Error: "..e)
end
local image = game.Players:GetUserThumbnailAsync(userid, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size150x150)
table.insert(data,{username,points,image})
end
ui.Parent = script
sf:ClearAllChildren()
ui.Parent = sf
for number,d in pairs(data) do
local name = d[1]
local val = d[2]
local image = d[3]
local color = Color3.new(1,1,1)
if number == 1 then
color = Color3.new(1,1,0)
elseif number == 2 then
color = Color3.new(0.9,0.9,0.9)
elseif number == 3 then
color = Color3.fromRGB(166, 112, 0)
end
local new = sample:Clone()
new.Name = name--Set name for better recognition and debugging
new.LayoutOrder = tonumber(number)
new.Image.Image = image--Set the image
new.Image.Place.Text = number--Set the place
new.Image.Place.TextColor3 = color--Set the place color (Gold = 1st)
new.PName.Text = name--Set the username
new.Value.Text = val--Set the amount of points
new.Value.TextColor3 = color--Set the place color (Gold = 1st)
new.PName.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)
wait(5)
end
Thank you so much!!!

5 comments
Check if the DataStorage returns an ID first. Simply just print userId
or replace "userid" with "username" in this line. This print is for debugging only anyway.
Thanks for the reply! The userid prints nil and the username prints [Failed To Load] (like it was referenced as above) with error "argument 1 missing or nil".
I think the problem is the datastore itself.
But I still can't find a solution...