Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to get userId from player name?

I am working on a game lobby that will allow player to join into a game if they search for a friends player name, but I have not been able to find any way to get the userId from the player's name. The two players will probably not be in the same lobby either.

This is what I have so far

local teleService = game:GetService("TeleportService")

module.GetPlayerLocation = function(playerName)
	local userId 
	--convert player's name (playerName) into their userId
	local success, errorMsg, placeId, instanceId = teleService:GetPlayerPlaceInstanceAsync(userId)
	if (success) then
		return placeId, instanceId
	else
		return false
	end
end

2 comments

0

Use the GetUserIdFromNameAsync function from the Players Service. http://wiki.roblox.com/index.php?title=API:Class/Players/GetUserIdFromNameAsync However, you will want to protect the script from breaking if someone were to place a invalid name.

0

Thanks

1 answer

✓ Accepted answer

You need to use this function:

int GetUserIdFromNameAsync (
    string userName
)

Hope this helps

This discussion is preserved as it was. New answers, comments, and votes are closed.