Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

What's wrong with my table.insert method where it adds every player that joins to the table?

contestants = {}
function join()
for _,v in pairs(game.Players:FindFirstChild()) do
	v = contestants(table.insert())
end
end
game.Players.PlayerAdded:connect(join)
game.Players.PlayerRemoving:connect(join)


if contestants == 1 then
	game.StarterGui.ScreenGui.Frame.TextLabel.Text = "test"
end

1 answer

You're using (almost) all incorrect syntax.

To get this to work the way you want, you should rewrite the code like this:

local contestants = {}

function join()
	contestants = game.Players:GetPlayers() -- :GetPlayers() (sometimes just :players()) to get all players in a table.
	-- Reset the table to just all players.
end

game.Players.PlayerAdded:connect(join)
game.Players.PlayerRemoving:connect(join)

wait(0.1)

join() -- For debugging mostly when using Play Solo.

while true do -- Infinite loop
	if #contestants == 1 then
		game.StarterGui.ScreenGui.Frame.TextLabel.Text = "test"
	else -- If there is less than 1 contestant, it will do this.
		game.StarterGui.ScreenGui.Frame.TextLabel.Text = ""
	end
	wait()
end

Also, it's table.insert(table, [index,] value), but since I didn't use it in my code, I'm showing it down here.

This discussion is preserved as it was. New answers, comments, and votes are closed.