Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to get userId from player name?

Asked by 8 years ago

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
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. M39a9am3R 3210 — 8y
0
Thanks CaptainRuno 40 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

You need to use this function:

int GetUserIdFromNameAsync (
    string userName
)

Hope this helps

Ad

Answer this question