Attempt to compare table <= number

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.

1 Like

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
1 Like

use the player amount in the loop and

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

Why ArE pEoPlE Not SCRIPTING on THE GUI ITSELF

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.