✓ Accepted answer
I think I got what you are trying to do.
Pause the game while there are not enough players in the server.
Your code is failing because of your use of if. if simply reads the value its given and runs code if its true, continues if its not. In order to pause the code until there are enough players you will need a repeating function. You can approach this many different ways.
#repeat loop method
repeat
print("Need more players")
wait()
until #game.Players:GetPlayers() > 2
This requires a check beforehand if you don't want to have it print Need more players if there are already enough players. So we will need an if statement.
if #game.Players:GetPlayers() < 2 then
repeat
print("Need more players")
wait()
until #game.Players:GetPlayers() > 2
end
This method is starting to get pretty bulky, repeat is better utilized for "pause this code until" situations with short wait times, luckily there are other methods.
#while loop method
while #game.Players:GetPlayers() < 2 do
print("Need more players")
wait()
end
That's it for this method. I'd recommend going with it.
There are other methods but these should be good enough to get you started. Hope this helped.
2 comments
Is it printing anything? also, something i would do and you should try is do Players:GetChildren() instead of Players:GetPlayers()
I think the reason it isnt working because all youre doing is just doing a print statement, what you could do isafter it is: elseif #game.Players:GetPlayers() > 2 then [your code here] end since you dont have anything checking if its more than 2 players