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
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
game.Players:GetPlayers()