Best way to lock servers?!

Hello all! I am curious on how to do what the title says. I believe I have thought of a way that would work, and I would like some feedback on this idea. I have looked around and seen some methods of locking a server, but I have never heard of doing this:

What if you locked a server by doing the following:
You run a method that sets the max players equal to the amount of players required, and after this event, a while true do loop will then update the max players every time someone leaves. For example, the player limit is reached, a game is started, and then someone leaves. The max player limit is then reduced to playerLimit - 1. Would this work?

I am unsure why you would user this here when you could use game.Players.PlayerRemoving. As for locking the server, you could have it so that the server checks the number of players when a player joins (game.Players.PlayerAdded), and if the number of players with the new player that just joined exceeds the MaximumPlayers count, then kicl the player with a message saying the server is full (player:Kick("Sorry, server is full!")). If you wan the MaximumPlayers count to reduce every time someone leaves the server, you could do that in the function bound to game.Players.PlayerRemoving.

Hope this helps :slight_smile:


Links:

2 Likes