Make servers unjoinable when 10 players join

I’m trying to make a game where 10 players need to join the game, then it starts, and you win when everyone else dies, but I want to make it so that you can’t join an already running server. Does anyone know how to do this? It would be greatly appreciated. Thanks!


Do you want a new round to start in the same server when everyone has died? In that case you could get away with just setting the server size to 10 not letting people join the current round if they join that server.

However, I suspect you want a completely different server which players cannot join at all while the round is in progress. For this you would need to use TeleportService, specifically ReserveServer and TeleportToPrivateServer.

With these methods, get the 10 players in the “hub” server, reserve a new Private Server using ReserveServer and teleport the 10 players to that server using TeleportToPrivateServer! :slight_smile:

You can read more about TeleportService here.


Try this, create a intvalue in a script in serverscriptservice, it should look like this;
Now for the code.

local Players = game:GetService("Players")
local max = 10 --max players
	if script.Numb.Value <= max then
		script.Numb.Value = script.Numb.Value +1
		print(script.Numb.Value.." is how many plrs after one connected") --this is an example
		if script.Numb.Value == max then
			player:Kick("Server full. Please join another.")  --this is an example of what it would do if it was 10 or more players, you can use teleport service as @mario118118 mentioned.
	script.Numb.Value = script.Numb.Value -1 --change the value, subtract one
	print(script.Numb.Value.." is how many plrs after one left") --what it does when the player leaves ( also can be used for debugging.)

Now the best solution would be to make it a 10 player server. But if you do not want to do this, then you can use this script. Good luck! Hope this helped.

1 Like

Ok, so I did use the TPService for teleporting from the Hub Place to the Map, so I’m familiar with this system. I didn’t know you could basically create a PrivateServer?

But the way I do it is:

When a player touches a platform in the hub-game, they get teleported to a random map, but they are in a waiting screen until the 10 players join, then when they die in the map, they’re teleported back, if that makes sense. So making a private server most likely wouldn’t work, unless there’s a way to make a method like Survivor? I’m not sure how you’d do that though. Thanks for the help!

So, this could work, other than the fact that I’m making a system where the players get teleported to another place when they die? I’m not sure how I could do that. Unless maybe I used a StringValue and listed off the players left, then when a new player joins, if the player’s name isn’t in there, you get kicked? Could this work? Thanks for the help!

I’ll remake the system to what you just said. Please make it clear in your post next time what you are attempting to achieve.

This seems possible with use of private servers and perhaps MessagingService.

Main server:

Keep track of current available server keys in table

When player touches pad, check for server
If server exists, send to available server
If not
Create a server, send the player to it and add it to the current servers

Listen to messaging service for a signal from a current server and remove from current servers list

Private servers:

Each time a player joins or leaves check the player count and send a message messaging service when either all players leave or it reaches 10 players

When a player dies teleport back to main server

Hope this made sense, kind of hard to explain it

Sorry about that, I meant to, just new to the forums lol. :slight_smile: Thanks so so much for the help! It’s greatly appreciated!

No problem, welcome to the forums! If there is anything else you want this to do, let us know now. So we can begin helping.

You could do like this:

local Teleportation = game:GetService(“TeleportService”)
Teleportation:Teleport(PLACEID, player)

Hey there! Would it be possible if, when you get time, you could send me an example of just how to send a message from one place to another using MessagingService? Thanks so so much! :slight_smile:

1 Like

I knew about that, I believe you misread what I said, I needed help with the joining a running server portion, not the dying. Thanks though! It’s understandable! :slight_smile:

Yup so, I think this is all I need right now, but if you don’t understand something, just please tell me, I’d be happy to answer your questions! :wink:

Heya. Sorry for the slightly slow response, I had to go and teach myself a little MessagingService :stuck_out_tongue:

Here’s some example code, and some descriptions from the wiki.

To summarize, send a message with a “key” like this:

MessagingService:PublishAsync(string topic, Variant message)

And listen for a specific key like this:

MessagingService:SubscribeAsync(string topic, Function callback)

For some reason, I found the data passed when subscribing is passed in a dictionary with the actual data and the time it was sent. Here’s an example which I wrote, and it works (in real servers, MessagingService doesn’t work into studio yet)


local msgService = game:GetService("MessagingService")

msgService:SubscribeAsync("Test", function(value) -- listen for a message
    print("recieved test message, message is " .. value["Data"] .. " and it was sent at " .. value["Sent"])

local function plrAdded(player)
    msgService:PublishAsync("Test", player.Name) -- send the player's name as a message with the same key

game.Players.PlayerAdded:Connect(plrAdded) -- player joins

for _,player in next, game.Players:GetPlayers() do -- just incase a player already joined

This example is listening for a message, which it also sends when a player joins (so the server listens for it’s own message, which is a bit silly). But of course in a real scenario you would send message and receive them from different servers.

It works in a single server, but can also be used in multiple server structures like yours :smiley:

Hey there! That’s understandable. I’m going to try editing that system to make a multi-server base. Thanks for the help! I’ll let you know how it ends up! :stuck_out_tongue:

1 Like

Awesome! Don’t forget to mark someone’s response as the solution, mine or someone else’s :slight_smile:

Why are you using an IntValue? Just have a PlayersIngame variable in the script.

I meant to reply to @Kensizo sorry!

Hey there, one question:

Would this work if I had your example exactly, however I added a Teleport function in when it senses a player is added? (It will wait for 1 second over and over again until 10 players join, then it’ll start the script?)

Uhh… not sure exactly what you mean, sorry. Teleport when it senses a player has been added??

This seems like a good way to structure the cross server messages. There’s no point in using a loop to check the player count in the private servers if you can check it when a player joins instead.

When a player joins check if the count is 10, if so start the game and send a message to the main server. When a player leaves check the count is 0, if so send a message to main server. When a player dies send them back to the main hub. This should work fine, but feel free to ask again if I just got a little confused.

Ok so here’s what I think you mean by the, “There’s no point in using a loop to check the player count in the private servers if you can check it when a player joins instead.”

   if #game.Players:GetPlayers() == 10 then
      game:GetService("TeleportService"):Teleport(PLACEID, player)