How to detect if GetUserIdFromNameAsync() is null

Like if I entered the name that doesn’t exist, how am I gonna get that information?

There is simple solution to that problem:
pcall function which can return certain value in case of error or success

Example of solution:

local result, errorId = pcall(function()
	print(game:GetService("Players"):GetUserIdFromNameAsync("GoofyNameHere"))
end)
-- result is boolean which can tell if there was error or not and errorId is the output of error code
if result then
	print("User found")
    -- successful
else
	print("User not found")
    -- not successful
end


pcall’s can be used in variety of ways but mainly just prevent erros from breaking the code. Hope that helped :slight_smile:

Thank you so much about pcall!!!1

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.