What i am trying to do is get the name of a player who donated to my game and then put them up on a leaderboard.

Code:

local lbData = game:GetService("DataStoreService"):GetOrderedDataStore("Board")

function AddCommas(num)
	return tostring(math.floor(num)):reverse():gsub("(%d%d%d)","%1,"):gsub(",(%-?)$","%1"):reverse()
end

function Update()
	local frames = workspace.Leaderboard.SurfaceGui.ScrollingFrame:GetChildren()
	for v,v in pairs(frames) do
		if v:IsA("Frame") then
			v:Destroy()
		end
	end
	for _,plr in next, game:GetService("Players"):GetPlayers() do
		pcall(function()
			lbData:UpdateAsync(plr.UserId, function() return plr:FindFirstChild("leaderstats"):WaitForChild("Donation").Value end) -- Change ("CurrencyNameHere") to the name of ya freaking currency
		end)
	end

	local data = lbData:GetSortedAsync(false,10)
	local page = data:GetCurrentPage()

	for rank, info in next, page do
		local frame = script.Parent.Sample:Clone()
		frame.Visible = true
		local plrName = game:GetService("Players"):GetNameFromUserIdAsync(info.key)		
		frame:WaitForChild("Place").Text = "#"..rank
		if rank == 1 then
			print("gold")
			frame.ImageColor3 = Color3.new(0.854902, 0.647059, 0.12549)
		elseif rank == 2 then
			print("gold")
			frame.ImageColor3 = Color3.new(0.854902, 0.647059, 0.12549)
		elseif rank == 3 then
			print("gold")
			frame.ImageColor3 = Color3.new(0.854902, 0.647059, 0.12549)
		elseif rank == 4 then
			print("gold")
			frame.ImageColor3 = Color3.new(0.854902, 0.647059, 0.12549)
		elseif rank == 5 then
			print("gold")
			frame.ImageColor3 = Color3.new(0.854902, 0.647059, 0.12549)
		elseif rank == 6 then
			print("gold")
			frame.ImageColor3 = Color3.new(0.854902, 0.647059, 0.12549)
		elseif rank == 7 then
			print("gold")
			frame.ImageColor3 = Color3.new(0.854902, 0.647059, 0.12549)
		elseif rank == 8 then
			print("gold")
			frame.ImageColor3 = Color3.new(0.854902, 0.647059, 0.12549)
		elseif rank == 9 then
			print("gold")
			frame.ImageColor3 = Color3.new(0.854902, 0.647059, 0.12549)
		elseif rank == 10 then
			print("gold")
			frame.ImageColor3 = Color3.new(0.854902, 0.647059, 0.12549)
		end

		frame.Username.Text = plrName
		frame.Value.Text = AddCommas(info.value)
		frame.Visible = true
		frame.Parent = workspace.Leaderboard.SurfaceGui.ScrollingFrame
	end
end

while true do
	Update()
	wait(3)
	wait(1)
	script.Parent.ScrollingFrame.Sample:Clone()
	script.Parent.ScrollingFrame.Sample:Destroy()

end

Main failing part:

local plrName = game:GetService("Players"):GetNameFromUserIdAsync(info.key)		

then it produces the error Players:GetUserIdFromNameAsync() failed: Unknown user

If there are any other details you need please let me know

2 comments

0

Wait, your error says you used "GetUserIdFromNameAsync()" but your script shows "GetNameFromUserIdAsync()". Can you post the correct and full error please?

0

GetUserIdFromNameAsync() failed: Unknown user thats what it gives me.