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

How do I use numplayers?

Asked by 11 years ago

Well if I spelled that numplayers wrong then whatever but anyways how do I use it? Do you have to use a for loop or something? Cause this is what I think you can use but with a numplayer function:

1for i = 1, 4 do
2    m = Instance.new("Hint", Workspace)
3    m.Text = "Waiting for 4 players to join."
4end

If you know a better way to do this or without a for loop than please help me. THANKS!

1 answer

Log in to vote
3
Answered by 11 years ago

game.Players.NumPlayers --> Returns an integer

For example:

01function PlayerEntered(player)
02    repeat wait() until player.Character
03    if game.Players.NumPlayers == 1 then -- If the number of players is 1
04        -- only one person here in the server
05    elseif game.Players.NumPlayers >= 2 then -- If the number of players is 2 or greater
06        -- there is two or more players in the server
07    end
08end
09 
10game.Players.PlayerAdded:connect(PlayerEntered)

You can also look in the Roblox Wiki.

Web page for NumPlayers: http://wiki.roblox.com/index.php?title=NumPlayers

Ad

Answer this question