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

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?

sorry for the late reply i went to bed
Capture
but when i print the userid it says nil lol? but when i just print the userid normally it says the id so im very confused i think

GetUserInfosByUserIdsAsync Only allows numbers so like 10302302
I dont think you can define a varaible for it and do
lcoal Userid = 12033023

because it might not be able to read it?

That could be the case. When you printed typeof(userId) what did it say?

It said Unable to cast to Array ?? im going crazy lol but im pretty sure
GetUserInfosByUserIdsAsync is unable to read the defined variable

I have a feeling the error is correct and the userid you are getting are invalid. When you tonumbered them, they returned nil so that might mean your userId variable contains something other than a number

Even though you printed the userid and it looked fine

When you printed the typeof(userId) it errored usbled to cast to array?

Capture

The rrror is implying that userId is not a number.

but it is a number though because if i just print the userid it prints it so really not sure what the issue is

Type string.len(userId) and check if there are extra spaces. Idk anymore. Can you show the code you used to save their data and how you created the key? I am running out of ideas

Gtg to school now so won’t respond for awhile. Other devs could give you a hand

1 Like

Instead of doing this

print(typeof(UserInfo[1].DisplayName))
print((UserInfo[1].DisplayName))

I just did this instead and it printed out the displayname
thanks for the help though and enjoy school buddy :+1: