Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 10 years ago
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

Log in to vote
1
Answered by
Tkdriverx 514 Moderation Voter
10 years ago

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.

Ad

Answer this question