I wanted to have the game I made not start until there are at the very least 2 players in the game. I have tried:
game:GetService("Players").PlayerAdded:Connect(function()
if (#game:GetService("Players"):GetPlayers() >= 2) then
-- Start the game
else
-- Tell the player that there needs to be at least 2 players to start
end
end)
The thing I am worried about is that if there are 2 players in the game and another player joins, the game would start from the beginning again. How would I modify the script in order to start the game when there are at least 2 players and will not start again if more join?
EDIT:
I have decided to use a boolean saved in a variable called debounce. This way when there are 2 players the game can start and if more join, the game will not restart again.
debounce = true
game:GetService("Players").PlayerAdded:Connect(function()
if (#game:GetService("Players"):GetPlayers() >= 2 and debounce) then
debounce = false
-- Start the game
else
debounce = true
-- Tell the player that there needs to be at least 2 players to start
end
end)
If there are other solutions, please let me know!

4 comments
syntax error at line 2; you're missing a parenthesis
Fixed
You can use a while loop for this. The loop will keep running as long as there are at least 2 players in the game.
I have decided to use a boolean inside a variable called debounce to fix the issue