Players:GetNameFromUserIdAsync() failed help

ive already fix the problem no need for other help

hello guys so i am making a leaderboard but then i keep getting this error

Players:GetUserIdFromNameAsync() failed: Unknown user

i did use pcall so that it dont make any errors
here is my entire script

local DataStoreService = game:GetService("DataStoreService")
local CoinsLeaderboard = DataStoreService:GetOrderedDataStore("CoinsLeaderboard")

local function updateLeaderboard()
        local success, errorMessage = pcall (function()
                local Data = CoinsLeaderboard:GetSortedAsync(false, 5)
                local CoinsPage = Data:GetCurrentPage()
                for Rank, data in ipairs(CoinsPage) do
			local userName = game.Players:GetNameFromUserIdAsync(tonumber(data.key)) ---here is where i am getting errors
			local Name = userName
                       local coins = data.value
                       local isOnLeaderboard = false
                       for i, v in pairs(game.Workspace.GlobalLead.LeaderPart.SurfaceGui.Holder:GetChildren()) do
                             if v.Player.Text == Name then
                                  isOnLeaderboard = true

                     if coins and isOnLeaderboard == false then
                            local newLbFrame = game.ReplicatedStorage:WaitForChild("Frame"):Clone()
                            newLbFrame.Player.Text = Name
                            newLbFrame.Coins.Text = coins
                            newLbFrame.Rank.Text = "#"..Rank
				newLbFrame.Position =, 0, newLbFrame.Position.Y.Scale + (50 * #game.Workspace.GlobalLead.LeaderPart.SurfaceGui.Holder:GetChildren()), 0)
				newLbFrame.Parent = game.Workspace.GlobalLead.LeaderPart.SurfaceGui.Holder

      if not success then

while true do

        for _, player in pairs(game.Players:GetPlayers()) do
              CoinsLeaderboard:SetAsync(player.UserId, player.leaderstats.Wins.Value)

	for _, frame in pairs(game.Workspace.GlobalLead.LeaderPart.SurfaceGui.Holder:GetChildren()) do



any help will be grateful

1 Like

if u didnt understand anything tell me

1 Like

The user probably is banned, or the key isn’t the user ID. Try printing the key to see if it is actually just numbers.

Yeah could you please tell us what the error message is.

The User Is Either Banned Or The User’s Account Has Been Deleted.

1 Like

Even if the player is banned it does not affect this api, I can still personally 2 years after my account terminated with the api get the information of it

What name are you looking for? try to print it in your console

Well doesn’t he say:

local userName = game.Players:GetNameFromUserIdAsync(tonumber(data.key))

He is trying to get a username from the data key right? Well wouldn’t the day key be a list of multiple player names, not one, because he is storing a leaderboard of multiple players.

Hoo shh I thought he put it in a for loop thanks

this is the error message

Players:GetUserIdFromNameAsync() failed: Unknown user

Did you try printing key? We all know what the error is, we just don’t know what is the value of key.

actually me neither i took the script from this video How to Make A Global Leaderboard in Roblox Studio - YouTube
i change some of its component then i got the error like it was working fine in the video.

Try printing the key so we can see. Also you shouldn’t really ask help on scripts you didn’t write but just print the key.

sorry for wasting your time but ive finally fixed it