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

If There are 2 Players On Server Start Game? [closed]

Asked by
GentiRob -81
6 years ago

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

Closed as Non-Descriptive by User#24403, Gey4Jesus69, ee0w, DinozCreates, and yHasteeD

This question has been closed because its title or content does not adequately describe the problem you are trying to solve.
Please ensure that your question pertains to your actual problem, rather than your attempted solution. That is, you were trying to solve problem X, and you thought solution Y would work, but instead of asking about X when you ran into trouble, you asked about Y.

Why was this question closed?

2 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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.

0
No, you should be using :GetPlayers() User#24403 69 — 6y
0
Thank you, I've changed it Icy_Qube 29 — 6y
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. TheOnlySmarts 233 — 6y
Ad
Log in to vote
0
Answered by
Mr_Unlucky 1085 Moderation Voter
6 years ago

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.")
0
Line 14 is completely pointless. User#24403 69 — 6y