Finding whether a player exists with :GetUserIdFromNameAsync()

Hello!
I’m working on revamping my ban system with displaying a thumbnail of the player that will be banned. The issue is that my output is spammed with "Players:GetUserIdFromName() failed because the user does not exist". Is there a way to get around this?

Here’s my script:

script.Parent.Changed:Connect(function()
	local userId = game.Players:GetUserIdFromNameAsync(script.Parent.Text)
	if userId then
		local thumbnailSize = Enum.ThumbnailSize.Size180x180
		local thumbnailType = Enum.ThumbnailType.AvatarBust
		local thumbnail, isReady = game.Players:GetUserThumbnailAsync(userId, thumbnailType, thumbnailSize)
		script.Parent.Parent.AvatarPreview.Image = thumbnail
	end
end)
2 Likes

If you just wanted to stop the errors, you could just wrap the code in a pcall().

If you want to stop the problem from occurring, instead of handling it when it does, can we see what “script.parent” actually is so we can understand how your ban system works?

1 Like

Tried using pcall, I guess I was doing it wrong haha. Thanks for that link! I will probably implement it elsewhere in the game as well.

1 Like