Players:GetUserIdFromNameAsync() failed: Unknown user - Server - leaderboardScript:40

I am setting the userId and when I print that userId it says the correct one, but then when i go in ipairs inside of the page, and use getnamefromuiseridasync, I put in v.key, and it prints out as -2, can someone help me?

Did you use .Name or .DisplayName? Did you enter a username from a player located in the player directory?

Can you share your script and full console error?

1 Like

whatever (v.key) is must not be the name of a valid player. Giving your the unknown user error because that string name doesn’t exist.

1 Like

local ds = game:GetService(“DataStoreService”)
local rbxLB = ds:GetOrderedDataStore(“rbxLB”)

local function updateLB()

local success, errormessage = pcall(function()
	local Data = rbxLB:GetSortedAsync(false, 100)
	local page = Data:GetCurrentPage()
	for i,v in ipairs(page) do
		print(tonumber(v.key))
		local userName = game.Players:GetNameFromUserIdAsync(tonumber(v.key))
		
		local Name = userName
		
		local RBX = v.value
		local isOnLB = false
		for i,v in pairs(workspace.RobuxLeaderboard.Main.SurfaceGui.Holder:GetDescendants()) do
			if v:IsA("Frame") then
			if v.User.Text == Name then
				isOnLB = true
				break
				end
				end
		end
		if RBX > 0 and isOnLB == false then
			
			local newPlrFrame = game.ReplicatedStorage.plrHolder:Clone()
			newPlrFrame.Parent = workspace.RobuxLeaderboard.Main.SurfaceGui.Holder
			newPlrFrame.Visible = true
			newPlrFrame.User.Text = Name
			newPlrFrame.Rank.Text = "#"..i
				newPlrFrame.Rbx.Text = tostring(RBX)
				
		end
	end
	
end)
if not success then
	warn(errormessage)
end

end

game.ReplicatedStorage.Events.updateLB.Event:Connect(function()
for i,v in pairs(game.Players:GetPlayers()) do
local char = v.Character or v.CharacterAdded:Wait()
local hrp = char:FindFirstChild(“HumanoidRootPart”)
rbxLB:SetAsync(v.UserId, hrp:FindFirstChild(“RBX”).Value)

end

for i,v in pairs(workspace.RobuxLeaderboard.Main.SurfaceGui.Holder:GetDescendants()) do
	if v:IsA("Frame") then
		v:Destroy()
	end
end
updateLB()

end)

Now it’s not even saying that, it says argument 1 missing or nil