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

game.Players.NumPlayers detection script not working?

Asked by
Mr_Unlucky 1085 Moderation Voter
5 years ago

I'm making a script where if the number of players is not 2 then the game will not run. However, it's not working. No errors either.

CODE:

while game.Players.NumPlayers < 1 do
    Status.Value = "Waiting for more players..."
    repeat wait (2) until game.Players.NumPlayers >- 1
end
Intermission()
0
You could use a value which it can increment or decrease by one every time a player is added or removed as I think NumPlayers is deprecated: http://wiki.roblox.com/index.php?title=API:Class/Players/NumPlayers Nikkasfied 43 — 5y

2 answers

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

game.Players.NumPlayers is deprecated. Use #game.Players:GetPlayers() instead

0
Not game.Players.NumPlayers. game:GetService("Players").NumPlayers. User#19524 175 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
function count()
    local numofPlayers = 0
    for j,k in pairs(game.Players:GetChildren()) do
        numofPlayers + 1
    end
    repeat wait() until numofPlayers == 2
    intermission()
end

game.Players.PlayerAdded:Connect(count)
game.Players.PlayerRemoving:Connect(count)
0
You should’ve be using GetChildren. You should be using GetPlayers. User#19524 175 — 5y

Answer this question