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

Numplayer does not work anymore. @@ can anyone help me what should i use instead?

Asked by 5 years ago
Edited by Azarth 5 years ago
Status.Value = "Waiting for enough players"

repeat wait(1) until game.Players.NumPlayers >= 2

Status.Value = "Intermission"

wait(10)

local plrs = {}

for i, player in pairs(game.Players:GetPlayers()) do
    if player then
        table.insert(plrs,player) -- Add each player into plrs table
    end
end

This is a script from youtube. Many people say its not working Well i look up on google and after a long time find out that the NumPlayers doesn't working any more. Can anyone hep me

p/s 5 days old script :V ( i do watch all peasfactory vid for basic still feel like a noob) and sorry for my poor English

3 answers

Log in to vote
0
Answered by
Azarth 3141 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

You can instead use the GetPlayers() method as stated on the NumPlayers page. GetPlayers returns a table of the players in the game, not to be confused with GetChildren() which will return anything in Players, even if the object is not a Player. Since the table is an array you can put # in front of it and it will tell you the number of indexes in the table.

local PlayersService = game:GetService('Players')
local minPlayers = 1

local plrs = {}

local function StartGame()
    for _, player in pairs(PlayersService:GetPlayers()) do
        if player then
            table.insert(plrs, player)
        end
    end
    for i = 5, 0, -1 do 
        print ( i )
        wait(1)
    end
end

local function StopGame()
    Status.Value = 'Intermission'
    -- reset table
    for i,v in pairs( plrs ) do
        plrs[i] = nil
    end
end


while true do 
    local NumPlayers = #PlayersService:GetPlayers()
    if NumPlayers >= minPlayers then 
        StartGame()
        StopGame()
    else
        local difference = minPlayers - NumPlayers
        Status.Value = ('Waiting for %d more %s'):format(difference, difference > 1 and 'players' or 'player')
    end
    wait( 1 )
end
0
Status.Value = "Waiting for enough players" local NPlayer = game.Players:GetPlayers() if NPlayer > 2 then wait(1) Status.Value = "Intermission" thinhs12 6 — 5y
0
I tried to fix on my own,but it says " attempt to compare number with table" thinhs12 6 — 5y
0
I tried to fix on my own,but it says " attempt to compare number with table" thinhs12 6 — 5y
0
Btw what " for i = 5, 0, -1 do " use for. @@ sr can u explain to me thinhs12 6 — 5y
0
It's #game.Players:GetPlayers(). For loop i = start, end, increment by num Azarth 3141 — 5y
Ad
Log in to vote
-1
Answered by
Alphexus 498 Moderation Voter
5 years ago

game.Players:GetPlayers()

0
I did Getplayer, but it doesnt wait til 2 second thinhs12 6 — 5y
Log in to vote
-1
Answered by
TopBagon 109
5 years ago

How about this

for i,v in pairs(game.Players:GetChildren()) do
    repeat wait(1) until v >= 2
end
0
v is the player, so no. Azarth 3141 — 5y

Answer this question