Leaderboard only lists a banned player and doesn't load their character

  1. What do you want to achieve?
    I’m trying to make a leaderboard list the top 100 people who have the most robux spent in my game and load the avatar for the number 1 player.

  2. What is the issue?
    While the leaderboard it self does work with the player listing and the character does load, the problem is that if a player is banned and they are on the leaderboard, let’s say they are number 1 and their user id is 40 (this user is a banned player), it will break and only list the banned player’s name on the leaderboard and not load their character. Specifically, the Player:GetHumanoidDescriptionFromUserId() function fails. I have received this error in the Output window of studio when joining my game: Imgur: The magic of the Internet I want to know how to make it so if the code can’t get the player’s character to not attempt to load the character and just leave the default character to be there. The default character in my game is already loaded and doesn’t need to be coded in.

  3. What solutions have you tried so far?
    I have tried to fix this but have gotten nowhere.

Here is my leaderboard code:

local DataStoreService = game:GetService("DataStoreService")
local RobuxSpentLeaderboard = DataStoreService:GetOrderedDataStore("RobuxSpentLeaderboard")
local LeaderboardHolder = game:GetService("Workspace"):WaitForChild("Map"):WaitForChild("Lobby"):WaitForChild("Leaderboards"):WaitForChild("RobuxSpentLeaderboard"):WaitForChild("Leaderboard"):WaitForChild("Holder")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UpdateInfo = game:GetService("Workspace"):WaitForChild("Map"):WaitForChild("Lobby"):WaitForChild("Leaderboards"):WaitForChild("RobuxSpentLeaderboard"):WaitForChild("UpdateInfo"):WaitForChild("BillboardGui"):WaitForChild("TextLabel")

local function UpdateLeaderboard()
	local success, errorMessage = pcall (function()
		local Data = RobuxSpentLeaderboard:GetSortedAsync(false, 100)
		local RobuxSpentPage = Data:GetCurrentPage()
		for Rank, data in ipairs(RobuxSpentPage) do
			local Username = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
			local Player = tonumber(data.key)
			local Name = Username
			local RobuxSpent = data.value
			local IsOnLeaderboard = false
			for i, v in pairs(LeaderboardHolder:GetChildren()) do
				if v.Player.Text == Name then
					IsOnLeaderboard = true
					break
				end
			end

			if RobuxSpent and IsOnLeaderboard == false then
				local NewLeaderboardFrame = ReplicatedStorage:WaitForChild("Leaderboards"):WaitForChild("RobuxSpent"):WaitForChild("LeaderboardFrame"):Clone()
				NewLeaderboardFrame.Player.Text = Name
				NewLeaderboardFrame.RobuxSpent.Text = RobuxSpent
				NewLeaderboardFrame.Rank.Text = "#"..Rank
				NewLeaderboardFrame.Position = UDim2.new(0.492, 0, NewLeaderboardFrame.Position.Y.Scale + (.009 * #LeaderboardHolder:GetChildren()), 0)
				NewLeaderboardFrame.Parent = LeaderboardHolder

				if Rank == 1 then
					local Humanoid = LeaderboardHolder.Parent.Parent:WaitForChild("Most Robux Spent"):WaitForChild(" "):WaitForChild("Humanoid")
					local HumanoidDescription = game:GetService("Players"):GetHumanoidDescriptionFromUserId(Player)
					Humanoid:ApplyDescription(HumanoidDescription)
				end
			end
		end
	end)

	if not success then
		error(errorMessage)
	end
end

while true do
	for _, player in pairs(game.Players:GetPlayers()) do
		RobuxSpentLeaderboard:SetAsync(player.UserId, player.OtherLeaderstats.RobuxSpent.Value)
	end

	for _, frame in pairs (LeaderboardHolder:GetChildren()) do
		frame:Destroy()
	end

	---

	UpdateLeaderboard()

	for i = 1,60 do
		UpdateInfo.Text = "Updates in "..60-i.."."
		wait(1)
	end

	UpdateInfo.Text = "Updating..."
end

Any help will be appreciated, thanks!

Could you maybe try using an If to destory him?

Could you explain in more detail about what you mean by using an if statement to destroy the player?

I have found the solution to my problem by adding another pcall inside the current pcall. This pcall tries to get the player’s character. If the pcall fails, it doesn’t do anything, else it loads the character.