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

How do I find the number of players in a game?

Asked by
NecoBoss 194
10 years ago

Okay so I need to find the amount of players in my game. Basically I want to use a if/then statement. Here is the type I want to use:

if AmountOfPlayers >= 2 then -- AmountOfPlayers is the part I don't know
game.Workspace.MainScript.Disabled = false
elseif AmountOfPlayers <= 1 then
game.Workspace.StringValue.Value = "Wait for more players"
end

1 answer

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

There is a property of the Players service called NumPlayers which is the number of players currently playing.


If you wanted to compute it yourself, it would be the number of Player objects inside the Players service:

local numPlayers = #game:GetService("Players"):GetPlayers();
Ad

Answer this question