Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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

5 comments

0

Status.Value = "Waiting for enough players" local NPlayer = game.Players:GetPlayers() if NPlayer > 2 then wait(1) Status.Value = "Intermission"

0

I tried to fix on my own,but it says " attempt to compare number with table"

0

I tried to fix on my own,but it says " attempt to compare number with table"

0

Btw what " for i = 5, 0, -1 do " use for. @@ sr can u explain to me

0

It's #game.Players:GetPlayers(). For loop i = start, end, increment by num

game.Players:GetPlayers()

1 comment

0

I did Getplayer, but it doesnt wait til 2 second

How about this

for i,v in pairs(game.Players:GetChildren()) do
	repeat wait(1) until v >= 2
end

1 comment

0

v is the player, so no.

This discussion is preserved as it was. New answers, comments, and votes are closed.