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.
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.
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