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

game.Players.NumPlayers detection script not working?

I'm making a script where if the number of players is not 2 then the game will not run. However, it's not working. No errors either.

CODE:

while game.Players.NumPlayers < 1 do
	Status.Value = "Waiting for more players..."
	repeat wait (2) until game.Players.NumPlayers >- 1
end
Intermission()

1 comment

0

You could use a value which it can increment or decrease by one every time a player is added or removed as I think NumPlayers is deprecated: http://wiki.roblox.com/index.php?title=API:Class/Players/NumPlayers

2 answers

game.Players.NumPlayers is deprecated. Use #game.Players:GetPlayers() instead

1 comment

0

Not game.Players.NumPlayers. game:GetService("Players").NumPlayers.

function count()
	local numofPlayers = 0
	for j,k in pairs(game.Players:GetChildren()) do
		numofPlayers + 1
	end
	repeat wait() until numofPlayers == 2
	intermission()
end

game.Players.PlayerAdded:Connect(count)
game.Players.PlayerRemoving:Connect(count)

1 comment

0

You should’ve be using GetChildren. You should be using GetPlayers.

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