local playerTable = game:GetService(“Players”):GetPlayers()
while true do
wait(5)
if (#playerTable < 2) then
print(“not enouhg players”)
else
print(“enough players”)
local randomPlayer1 = playerTable[math.random(1, #playerTable)]
It’s suppose to find two random players from players and print their names but if there is not enough players in the table it prints not enough players.
You never update playerTable so it’s always empty. The proper code would be:
local playerTable = game:GetService(“Players”):GetPlayers()
while true do
wait(5)
if (#playerTable < 2) then
print(“not enouhg players”)
else
print(“enough players”)
local randomPlayer1 = playerTable[math.random(1, #playerTable)]
table.remove(playerTable, table.find(playerTable, randomPlayer1))
local randomPlayer2 = playerTable[math.random(1, #playerTable)]
print(randomPlayer1.Name .. randomPlayer2.Name)
end
playerTable = game:GetService("Players"):GetPlayers()
end