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

If There are 2 Players On Server Start Game?

Anyone can help please? Im trying to do game.Players.NumPlayers > 2 do print("There are enough players") else print("Need more players")

pls help

2 answers

Just created a table with game.Players:GetPlayers() then compared the value of #allPlrs with 2

local allPlrs = game.Players:GetPlayers()


if #allPlrs > 2 then
	print("There are enough players")
else
	print("Need more players")
end

I'm not the best with explaining anything, but hope this helps you understand a bit.

3 comments

0

No, you should be using :GetPlayers()

0

Thank you, I've changed it

0

Good but on line 4, since he wants 2 players or more, so >= instead of just >, doing just this means the number has to be 3 or higher to start the game.

NumPlayers is deprecated. Here's what you can do instead

local Players = game:GetService("Players")
local PlayerCount = 0

Players.PlayerAdded:Connect(function()
	PlayerCount = PlayerCount + 1
end)

Players.PlayerRemoving:Connect(function()
	PlayerCount =PlayerCount - 1
end)

while PlayerCount < 1 do
	print("Not enough players.")
	repeat wait(1) until PlayerCount > 1
end

print("Enough players.")

1 comment

0

Line 14 is completely pointless.

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