How can I tell if an id is a real player id? I'm making a gui where you can enter a player id and be morphed into the player.
COMMUNITY QUESTION
How can I tell if an id is a real player id?
1 answer
You can use GetNameFromUserIdAsync which will return the players name associated with the given id or error if that player id is not found so it needs to be wrapped in a pcall
Pcall will run the given function with the passed arguments and return if the code executed without any errors and any returned arguments the function itself returned.
Example
local plrServ = game:GetService('Players')
local function isValidPlayerId(id)
-- calls the function GetNameFromUserIdAsync which is passed the players service to remove the need for ':' and the id passed
local res, _ = pcall(plrServ.GetNameFromUserIdAsync, plrServ, id)
return res -- we know the user id is valid if the code runs successfully
end
print(isValidPlayerId(-213)) -- prints false
print(isValidPlayerId(213)) -- prints true
I hope this helps
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
http://wiki.roblox.com/index.php?title=API:Class/Player/UserId This has some of it