Players.NumPlayers to Players:GetPlayers()

I know NumPlayers is Depreciated but i think Using GetPlayers() would be better.
Ive tried but i dont know how to.
Im using it for a sword round based game.

repeat wait() until game.Players.NumPlayers >= 2
    	Status.Value = "Intermission"
    	wait(1)
    	Status.Value = "(30)"
    	wait(1)
    	Status.Value = "(29)"
    	wait(1)
    	Status.Value = "(28)"
    	wait(1)
    	Status.Value = "(27)"
    	wait(1)
    	Status.Value = "(26)"
    	wait(1)
    	Status.Value = "(25)"
    	wait(1)
    	Status.Value = "(24)"
    	wait(1)
    	Status.Value = "(23)"
    	wait(1)
    	Status.Value = "(22)"
    	wait(1)
    	Status.Value = "(21)"
    	wait(1)
    	Status.Value = "(20)"
    	wait(1)
    	Status.Value = "(19)"
    	wait(1)
    	Status.Value = "(18)"
    	wait(1)
    	Status.Value = "(17)"
    	wait(1)
    	Status.Value = "(16)"
    	wait(1)
    	Status.Value = "(15)"
    	wait(1)
    	Status.Value = "(14)"
    	wait(1)
    	Status.Value = "(13)"
    	wait(1)
    	Status.Value = "(12)"
    	wait(1)
    	Status.Value = "(11)"
    	wait(1)
    	Status.Value = "(10)"
    	wait(1)
    	Status.Value = "(9)"
    	wait(1)
    	Status.Value = "(8)"
    	wait(1)
    	Status.Value = "(7)"
    	wait(1)
    	Status.Value = "(6)"
    	wait(1)
    	Status.Value = "(5)"
    	wait(1)
    	Status.Value = "(4)"
    	wait(1)
    	Status.Value = "(3)"
    	wait(1)
    	Status.Value = "(2)"
    	wait(1)
    	Status.Value = "(1)"
    	wait(0.5)
    	
    	local plrs = {}
    	
    	for i, player in pairs (game.Players:GetPlayers()) do 
    		if player then 
    			table.insert(plrs,player)--Add each players into plrs table
    		end
    	end
2 Likes

game.Players:GetPlayers() returns an array of players already in the game. You don’t need to insert them into a separate array, unless you have a different use case than just keeping track of the players.

You can do

#game.Players:GetPlayers()

to figure out how many players are in the game.

1 Like

To replace that, use #game.Players:GetPlayers().

Also we can replace the intermission with a for loop.


repeat wait() until #game.Players:GetPlayers() >= 2

Status.Value = "Intermission"
wait(1) -- uberwoops
for i = 30, 0, -1 do
    Status.Value = "(" .. i  .. ")"
    wait(1)
end
wait(0.5) -- did you want this?

local plrs = game.Players:GetPlayers() -- lol skip the for loop to add the players into a new table, we created one right now
10 Likes

Thank you so much! You made my code cleaner and up to date

Use repeat Players.PlayerAdded:Wait() instead of repeat wait().

2 Likes