Answered by
7 years ago Edited 7 years ago
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
01 | local plrServ = game:GetService( 'Players' ) |
03 | local function isValidPlayerId(id) |
05 | local res, _ = pcall (plrServ.GetNameFromUserIdAsync, plrServ, id) |
09 | print (isValidPlayerId(- 213 )) |
10 | print (isValidPlayerId( 213 )) |
I hope this helps