I have a global leaderboard in my game that works perfectly and now i’m trying to get it to also display an image of the player with the rank, but when I edit the script to do so, it just does not work, and does not show anything, can somebody please help me on this? Also, it does not come out with errors so I can’t see what’s wrong.
Script:
local ds = game:GetService("DataStoreService")
local coinsODS = ds:GetOrderedDataStore("CoinsStats")
local timeUntilReset = 10
while wait(1) do
timeUntilReset = timeUntilReset - 1
script.Parent.Parent.ResetTime.Text = "Resetting in " .. timeUntilReset .. " seconds..."
if timeUntilReset == 0 then
timeUntilReset = 10
for i, plr in pairs(game.Players:GetPlayers()) do
coinsODS:SetAsync(plr.UserId, plr.leaderstats.Survivals.Value)
end
for i, leaderboardRank in pairs(script.Parent:GetChildren()) do
if leaderboardRank.ClassName == "Frame" then
leaderboardRank:Destroy()
end
end
local success, errorMsg = pcall(function()
local data = coinsODS:GetSortedAsync(false, 10)
local coinsPage = data:GetCurrentPage()
for rankInLB, dataStored in ipairs(coinsPage) do
local name = game.Players:GetNameFromUserIdAsync(tonumber(dataStored.key))
local userid = (tonumber(dataStored.key))
local coins = dataStored.value
local thumbType = Enum.ThumbnailType.AvatarBust
local getthumbnail, isReady = game.Players:GetUserThumbnailAsync(userid, thumbType)
local template = script.Template:Clone()
template.Name = name .. "Leaderboard"
template.PlrName.Text = name
template.Rank.Text = "#" .. rankInLB
template.Coins.Text = coins
template.PlrIcon.Image = getthumbnail
template.Parent = script.Parent
end
end)
end
end
that cant be true though because im only trying to get the user id, making the player thumbnail, and setting the image with the thumbnail of the usedrid, maybe its something wrong with me trying to get the uder id but since i’m not to advanced at scripting i dont really know
i actually printed the dataStored.key and its correct but i dont know why it isnt setting the image to the players thumbnail even though it already has the thumbnail defined with the user id
No. It would be print(errorMessage). Your full code after the modifications should look like this:
local ds = game:GetService("DataStoreService")
local coinsODS = ds:GetOrderedDataStore("CoinsStats")
local timeUntilReset = 10
while wait(1) do
timeUntilReset = timeUntilReset - 1
script.Parent.Parent.ResetTime.Text = "Resetting in " .. timeUntilReset .. " seconds..."
if timeUntilReset == 0 then
timeUntilReset = 10
for i, plr in pairs(game.Players:GetPlayers()) do
coinsODS:SetAsync(plr.UserId, plr.leaderstats.Survivals.Value)
end
for i, leaderboardRank in pairs(script.Parent:GetChildren()) do
if leaderboardRank.ClassName == "Frame" then
leaderboardRank:Destroy()
end
end
local success, errorMsg = pcall(function()
local data = coinsODS:GetSortedAsync(false, 10)
local coinsPage = data:GetCurrentPage()
for rankInLB, dataStored in ipairs(coinsPage) do
local name = game.Players:GetNameFromUserIdAsync(tonumber(dataStored.key))
local userid = (tonumber(dataStored.key))
local coins = dataStored.value
local thumbType = Enum.ThumbnailType.AvatarBust
local getthumbnail, isReady = game.Players:GetUserThumbnailAsync(userid, thumbType)
local template = script.Template:Clone()
template.Name = name .. "Leaderboard"
template.PlrName.Text = name
template.Rank.Text = "#" .. rankInLB
template.Coins.Text = coins
template.PlrIcon.Image = getthumbnail
template.Parent = script.Parent
end
end)
print(errorMsg)
end
end
Since that error is somewhat nonspecific instead of printing the output of the pcall we can trace it directly to the line by commenting the pcall out.
local timeUntilReset = 10
while wait(1) do
timeUntilReset = timeUntilReset - 1
script.Parent.Parent.ResetTime.Text = "Resetting in " .. timeUntilReset .. " seconds..."
if timeUntilReset == 0 then
timeUntilReset = 10
for i, plr in pairs(game.Players:GetPlayers()) do
coinsODS:SetAsync(plr.UserId, plr.leaderstats.Survivals.Value)
end
for i, leaderboardRank in pairs(script.Parent:GetChildren()) do
if leaderboardRank.ClassName == "Frame" then
leaderboardRank:Destroy()
end
end
--local success, errorMsg = pcall(function()
local data = coinsODS:GetSortedAsync(false, 10)
local coinsPage = data:GetCurrentPage()
for rankInLB, dataStored in ipairs(coinsPage) do
local name = game.Players:GetNameFromUserIdAsync(tonumber(dataStored.key))
local userid = (tonumber(dataStored.key))
local coins = dataStored.value
local thumbType = Enum.ThumbnailType.AvatarBust
local getthumbnail, isReady = game.Players:GetUserThumbnailAsync(userid, thumbType)
local template = script.Template:Clone()
template.Name = name .. "Leaderboard"
template.PlrName.Text = name
template.Rank.Text = "#" .. rankInLB
template.Coins.Text = coins
template.PlrIcon.Image = getthumbnail
template.Parent = script.Parent
end
--end)
end
end
You should get an error this time as well as a line that the error occurred at. Find the line and then send the line that’s throwing the error.
local thumbType = Enum.ThumbnailType.AvatarBust
local thumbSize = Enum.ThumbnailSize.Size420x420
local getthumbnail, isReady = Players:GetUserThumbnailAsync(userid, thumbType, thumbSize)