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

Get Children Printing Not Working?

Asked by 10 years ago
function PlayerCount()

    PlayerCount = game.Players:GetChildren()

    for PlayerCountLoop = 1, #PlayerCount do
        leaderstats = (PlayerCount[PlayerCountLoop]:WaitForChild("leaderstats"))

        print(PlayerCount[PlayerCountLoop].Name .. "'s Stats")
        print(leaderstats.Attack.Value.. " - Attack")
        print(leaderstats.Defense.Value.. " - Defense")
        print(leaderstats.Agility.Value.. " - Agility")
        print(leaderstats.Energy.Value.. " - Energy")
        print(leaderstats["Power Level"].Value.. " - Power Level")

        if #PlayerCount < 2 then
            print("Wait For Another Player")
        elseif #PlayerCount > 1 then
            print("We May Begin!")
        end
    end
end

game.Players.PlayerAdded:connect(PlayerCount)

It is printing 'We May Begin!' twice, once when one player joins. Another time when another player joins. I tested it with my friend.

0
You could try greater than or equal to 2. Not sure why this is doing it. wjs3456 90 — 10y

1 answer

Log in to vote
0
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
10 years ago

I'm not sure what you're trying to do here, but connecting this to the PlayerAdded event is not a good way to go about this.

Try using this loop:

while wait() do
    if Game.Players.NumPlayers < 2 then
        print("Not enough players")
        Game.Players.PlayerAdded:wait()
    else
        --run game code
    end
end
0
Is NumPlayers a property? Do I erase the for loop? BosswalrusTheCoder 88 — 10y
0
This loop should be able to entirely replace your own. adark 5487 — 10y
0
Yeah, you dont ":GetChildren()" to count the player amount. Its game.Players.NumPlayers. Hybric 271 — 10y
0
@hybric; Numplayers didn't always exist, you know adark 5487 — 10y
Ad

Answer this question