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 10 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:

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

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 10 years ago

game.Players.NumPlayers --> Returns an integer

For example:

function PlayerEntered(player)
    repeat wait() until player.Character
    if game.Players.NumPlayers == 1 then -- If the number of players is 1
        -- only one person here in the server
    elseif game.Players.NumPlayers >= 2 then -- If the number of players is 2 or greater
        -- there is two or more players in the server
    end
end

game.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