"nil" error when trying to find something with square brackets?

  1. What do you want to achieve? I want to check to see if a UI object exists

  2. What is the issue? Trying to do so results in an error: (Player Name) is not a valid member of ScrollingFrame

Here’s my code:

local currentPlayerListButton = playerList[player.Name]
		if currentPlayerListButton == nil then
			createNewPlayerInList(player)
		end
  1. What solutions have you tried so far? I’ve tried checking by first making this a variable, which didn’t help solve the problem.

I feel like I’m missing something really obvious lol. Thanks in advance for help.

Try using Instance:FindFirstChild() instead. If it doesn’t find it, it will return nil without erroring.

1 Like

literally the error says it all… “Player Name is not a valid member of ScrollingFrame.” Use a player variable to get the player, then add them in by their name.

if not playerList:FindFirstChild(player.Name) then
	createNewPlayerInList(player)
end

What the first reply stated then applied to your example.