I can't insert a player obj into an empty table?

I’m making a round-based game and the code snippet below checks if there are enough players to start the round with.

However, after a few tries of getting this to work, this error pops up this line:


[ServerScriptService.GameLogic.GameLoop:51: attempt to call a nil value]

I assume that the table is being considered as a nil value, but why can’t I just insert the player object into it? I’ve tried looking through the documentation and find topics in the forum, but I can’t seem to find the solution. I appreciate any feedback on my code and solve this issue.

local eligiblePlayers = {}
-- Checks if there are less than four players
while #eligiblePlayers < 4 do
	for _,player in pairs(Players:GetPlayers()) do
		local inLobby = player:WaitForChild("PlayerBools"):WaitForChild("inLobby")
			print(player.Name.." "..tostring(inLobby.Value))
		if inLobby then
	print("there are less than 4 players in the lobby")

Try de-capitalizing Insert in “table.Insert”, as the correct syntax is “table.insert”. I’m not sure if this will solve the issue, but it might.


you never specify the table to insert!

Your reply kind of didn’t make sense to me, could you please make it more clear?

table.insert(eligiblePlayers, eligiblePlayers.Length + 1, player)

This shouldn’t be the cause of the issue. The number position parameter is completely optional.


1 Like

I wouldn’t have found that typo late at night! Thank you!

The error made sense now because it was calling a function that doesn’t exist, which returned nil.

1 Like