while true do Status.Value = "Waiting for enough players" game.Players:GetPlayers() repeat wait(1) until Players >= 2 Status.Value = "Intermission"
I know this is very wrong but this is deprecated
repeat wait() until game.Players.NumPlayers >= 2
In adaptation to yHasteeD's recommendation of: "you can simple use: repeat wait() until #game.Players:GetPlayers() >= 2"
Since that'd just run once and not account for a potential player drop (players leaving)
You could do:
local players = game.Players function playerAdded() local plramount = #players:GetPlayers() if plramount>=2 then game() end end players.PlayerAdded:connect(playerAdded) function game() -- game stuff here, make all functions in game end if #players:GetPlayers() < 2 end
The function you're looking for is a function of Players called GetPlayers
https://developer.roblox.com/api-reference/function/Players/GetPlayers
repeat wait() until game.Players:GetPlayers() >= 2
local Players = game:GetService("Players") local PlayerCount = 0 game.Players.PlayerAdded:Connect(function() PlayerCount = PlayerCount + 1 end) game.Players.PlayerRemoving:Connect(function() PlayerCount = PlayerCount - 1 end) while PlayerCount < 1 do repeat wait(1) until PlayerCount >= 2 end
There are many ways of doing this but I just went with my method. Accept if this helped :)
local players = {} function get_players() players = {} for _, a in pairs(game:service'Players':players'') do --// gets all players table.insert(players, a) --// inserts all player to the table end return #players --// returns the count of players end repeat wait() until get_players() >= 2