How could I limit the player count inside certain games in a universe?

Hello DevForum!

I’m interested in making a party system similar to Tower Defense Simulator or Tower Battles, where the lobby’s max player count is generally pretty high, whilst when teleporting to the round the max player account is usually the number of players inside the round, preventing anyone else from joining that server unless they leave or get teleported back to the lobby. I’m not the most experienced in scripting, and I haven’t really found much information about this on the internet, so is there any leads or advice you guys can give me so I can build upon from there?

Thanks!

Heya! What I think you’re looking for is TeleportService’s TeleportToPrivateServer function? What this does, is it teleports a variety of players (Or the players that want to start a round inside the lobby), and other players won’t be able to join them unless, as you said:

There are a couple things to note about using TeleportToPrivateServer though:

  • You’d have to call TeleportService’s ReserveServer function in order to create a private server

  • You’ll have to require a specific table of players that you want to teleport (You can do this by implementing some sort of sanity check)

Since you want to teleport players that want to start a round, you could potentially do something like this? Of course, you’ll have to check who wants to get teleported specifically:

local TPService = game:GetService("TeleportService")
local OtherPlaceID = 0000000 --Do keep in mind that this has to be in the same place universe for it to work

local function TeleportPlayers()
    local Code = TPService:ReserveServer(OtherPlaceID) --Now we're created our Reserved Server
    local PlayersWaiting = {} --The players that are currently waiting for the round to start

    for _, Player in pairs(game.Players:GetPlayers()) do
        if Player.WaitingForRound.Value == true then -- Say we create a BoolValue that's called "WaitingForRound" inside the player object, we're detecting if it's value is set as true or not to properly teleport them
            table.insert(PlayersWaiting, Player) -- Now here, we're inserting a value into the table
        end
    end

    TPService:TeleportToPrivateServer(OtherPlaceID, Code, PlayersWaiting) --Now that we've checked for all players, we can teleport only the specific ones
end

I believe it’s something along the lines of this hopefully :thinking:

2 Likes

Wow, thank you so much for the explanation! This will really help me in my game! :coefficients:

1 Like

Do keep in mind though that you’ll have to properly connect the function TeleportPlayers() in order for it to work, and that you’ll need to create a BoolValue for every Player that’s called WaitingForRound inside every Player Object

game.Players.PlayerAdded:Connect(function(Player)
    local Bool = Instance.new("BoolValue")
    Bool.Name = "WaitingForRound"
    Bool.Parent = Player
end)

Also, do keep in mind that I am just giving examples, the rest you’d need to figure out on your own :wink:

1 Like

Alrighty, thanks for the help! :wink: