Script to check player count not working

What I’m trying to accomplish is to check the player count. If it’s equal or greater than 2, it should print “Player count is equal or greater than 2!”. But this doesn’t work when I test it with a local server. Is it the script that’s wrong or how I’m testing it? All help appreciated!

local minPlayersRequired = false
local players = game.Players:GetChildren()

function checkPlayerCount()
	if #players >= 2 then
		minPlayersRequired = true
	end
end

repeat print("Player count checked") checkPlayerCount() wait(3) until minPlayersRequired == true

if minPlayersRequired == true then
	print("Player count is equal or greater than 2!")
end

The reason why it’s not working, is cause you’re only getting all of the player’s stuff once, which is possibly resulting why your function is not passing through it’s if statement

Try this and see if that changes anything?

local minPlayersRequired = false
local players = game:GetService("Players")

function checkPlayerCount()
	if #players:GetPlayers() >= 2 then
		minPlayersRequired = true
	end
end

repeat 
    print("Player count checked") 
    checkPlayerCount() 
    wait(3) 
until minPlayersRequired == true

if minPlayersRequired == true then
	print("Player count is equal or greater than 2!")
end
2 Likes