What am I doing wrong here?

Hi there,

I am attempting to make something where I can type a player’s name into a TextBox, and it would search to see if that particular player is in the game.

However, an error comes out of this whenever I try to search:
Line 5: attempt to call a userdata value

Here is the code: (This is inside of a localscript)

	local name = script.Parent.Parent.enterName.Text
	print("searching for player "..name)
	if game.Players(name) == nil then
		print("player not found!")
		print("player "..name.." was found!")

Any help would be appreciated!

You’re calling the PlayerService as a function on the 5th line, as well as checking to see whether it’s nil (i.e. not present) when your following code wants it to be present:


You need to do the following:

if game.Players:FindFirstChild(name) then
--> Player found
--> Player not found
1 Like

Thanks a lot! It worked. :slight_smile:

1 Like