How do you get the players display name in-game?

Trying to figure out how to get the players displayname with GetUserInfosByUserIdsAsync

I tried this before but i wanted to show you that it doesnt work.

When im in-game nothing even shows up on the leaderboard anymore so…

The function is a member of UserService not Players

Capture

It should be

game:GetService(“UserService”):GetUserInfosByUserIdsAsync

The function is a part of the UserService not Players.

They might have made a mistake when typing the example code

What line is the error on?—————-

for _, data in ipairs(page) do

Is it on that line?

I suggest adding print statements to debug

its on line 78 its the line thats

local UserInfo = game:GetService("UserService"):GetUserInfosByUserIdsAsync({userId})
local UserInfo = game:GetService("UserService"):GetUserInfosByUserIdsAsync({166802666}) 
-- returns a table with table inside. The table inside contains the data you want.

local UserInfo = game:GetService("UserService"):GetUserInfosByUserIdsAsync({166802666})

print(UserInfo[1].DisplayName)

The output
image

The output doesnt show the display name also the
Capture
If i change that to

local userId = data.key
local UserInfo = game:GetService("UserService"):GetUserInfosByUserIdsAsync(userId)

It says unable to cast to arrray
so idk

Sorry I made a mistake in the code refer back to the previous reply I made. I editted it

the error says you have an invalid userid. Add a print statement which prints your UserID variable

Capture
the userid is there just dont know why its not working lol

Replace the UserID variable with an actual userid. Does it work? Also try printing the type of the UserID variable print(typeof(UserID)) it should be a number.

Try adding tonumber(UserID)

it only works if i just do

local UserInfo = game:GetService("UserService"):GetUserInfosByUserIdsAsync({1326738568})

but i cant do that because im trying to get the display name of the user that has donated the most so idk

Print the type of UserID and tonumber it.

when i do

print(tonumber(userId))

it prints the userid but not sure why its not working when i do
GetUserInfosByUserIdsAsync({userId}) lol

Sorry I was away from my device. Now try setting userId to a number and then put that edited userId in the parameter of the GetUsersInfo function.

userId = tonumber(userId)

`o

local UserInfo = game:GetService("UserService"):GetUserInfosByUserIdsAsync({userId})

https://developer.roblox.com/en-us/api-reference/property/Player/DisplayName

Did you forget about this? Just save a player’s “DisplayName” property whenever they donate to the game.

How would i save the players display name if GetUserInfosByUserIdsAsync doesnt work?