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

Get Children Printing Not Working?

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.

1 comment

0

You could try greater than or equal to 2. Not sure why this is doing it.

1 answer

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

5 comments

0

Is NumPlayers a property? Do I erase the for loop?

0

This loop should be able to entirely replace your own.

0

Yeah, you dont ":GetChildren()" to count the player amount. Its game.Players.NumPlayers.

0

@hybric; Numplayers didn't always exist, you know

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