I’m trying to check the number of players in the game
local players = game.Players:GetPlayers()
local rep = game:GetService("ReplicatedStorage")
local sg = game.Players.LocalPlayer.PlayerGui:WaitForChild("Waiting")
while true do
if players <= 1 then
print("Not Enough Players")
sg.Enabled = true
else
if players > 1 then
sg.Enabled = false
break
end
end
end
For some reason, I keep getting the error “attempt to compare table <= number” at
if players <= 1 then
I’ve tried many solutions but couldn’t find a fix.
Use #players instead. This is the amount of items in the array of players.
Also it looks like your code will crash because there is no wait in the while loop!
local players = game.Players:GetPlayers()
local rep = game.ReplicatedStorage
local sg = game.Players.LocalPlayer.PlayerGui:WaitForChild("Waiting")
while sg.Enabled do
sg.Enabled = #players <= 1 -- '#' gets the amount of items in the list
task.wait(1)
end
local rep = game:GetService("ReplicatedStorage")
local sg = game.Players.LocalPlayer.PlayerGui:WaitForChild("Waiting")
while true do
local players = #game.Players:GetPlayers()
if players <= 1 then
print("Not Enough Players")
sg.Enabled = true
else
if players > 1 then
sg.Enabled = false
break
end
end
end