Group teleport system

I am trying to make a group teleport system like camping (the best example I could think off) I searched everywhere but I am still not able to find a article that I could understand. I am sorry if this is quite like my other post but I decided to keep it simple first. I really want to know how all those camping games allowed the players to be teleported to a empty seat and when the seats are full the players would get teleported into a reserved server or something like that.

I looked at lots of tutorials like YouTube wiki and devforum. I also used those articles that the people sent me on the other post but I am unable to understand how I am able to modify it to fit my system. I don’t get how they worked even though I read them lots of times. Most of them just teleport the players into other places in the game separately.

Is anyone able to explain it and maybe give me a example of it?

If there are any problems in this post please reply to me down below.

7 Likes

Have a look at ReserveServer and TeleportToPrivateServer.

You would create a table with the players who are in the seats at the end of the timer or when all seats are full and then reserve a server and loop through the players, teleporting them to the PrivateServer.

4 Likes

Are you able to teach me how to do it? I don’t really understand what you just said.

1 Like

There are two functions you can use to achieve this, ReserveServer and TeleportToPrivateServer

What we should do first is create a new server using ReserveServer

local newServer = TeleportService:ReserveServer(game.PlaceId) --this returns a code we can teleport to

Once the new server has been reserved, we can teleport everyone to the reserved server using the code

TeleportService:TeleportToPrivateServer(game.PlaceId, newServer, Players:GetPlayers())

This will teleport everyone to the same server, given the player limit is high enough

3 Likes

Sorry if this does not answer your original query, but I don’t quite get what you mean. Taking on @xuefei123’s suggestion:

ReserveServer is a method that allows you to create a special, reserved server of your game - sort of like a VIP server, but without a player having to buy it. These reserved servers don’t show up on your game page under “servers” and can only be joined by using TeleportToPrivateServer.

For example, imagine you have a party of four players, PlayersToTeleport. All the elements of that table are Player objects. This means you could manually do:

local PlayersToTeleport = {
    game.Players.Technoles,
    game.Players.Builderman,
    game.Players.RafDev,
    game.Players.xuefei123
}

Ideally, you’d get this table/array/list of players through another system though, such as using the Occupant property of all Seats in a campfire - however, that is beside the scope of your question.

Now that you have your players, you need to reserve a server for them so they can play together. You can achieve this by using:

local code = game:GetService("TeleportService"):ReserveServer(game.PlaceId) -- you can use a different place ID if you want to take them to another place within the same universe

Note this method returns a special code that identifies the created server.

Finally, after you have reserved a server for your players, all you have to do is take them there. Do the following:

game:GetService("TeleportService"):TeleportToPrivateServer(game.PlaceId, code, PlayersToTeleport)

Please let me know if you don’t understand something I’ve said, I tried to explain the best I could.


EDIT: I’m providing a larger snippet on how you could make my above example work. Obviously, there are better ways to do this, but I think this is the easiest way to comprehend.

Assuming the following hierarchy:
image

Putting the following script in ServerScriptService:

local PlaceId = 123456 -- the place ID for the actual game; must be in the same universe

if not game:IsLoaded() then
    game.Loaded:Wait()
end

local WorkspaceChildren = workspace:GetChildren()

for key, value in pairs(WorkspaceChildren) -- goes through all children of workspace
    if value:IsA("Model") and value.Name == "Tent" then
        local AlreadyStarting = false
        local ClickDetector = value.StartGame.ClickDetector
        ClickDetector.MouseClick:Connect(function()
            if AlreadyStarting then return end
            AlreadyStarting = true
            local PlayersToTeleport = {}
            for _, Seat in pairs(value:GetChildren()) do
                if Seat:IsA("Seat") and Seat.Occupant then
                    table.insert(PlayersToTeleport, Seat.Occupant)
                end
            end
            local code = game:GetService("TeleportService"):ReserveServer(PlaceId)
            game:GetService("TeleportService"):TeleportToPrivateServer(PlaceId, code, PlayersToTeleport)
        end)
    end
end
5 Likes

Spent ~10 minutes making this for you.

How this works is that whenever someone sits down on one of the seats, it starts a countdown if there isn’t one already. If they get off the seat, it cancels the countdown.

At the end of the countdown, it teleports all remaining candidates if there are more than X amount.

If during the countdown everyone gets off the seats, it cancels the countdown and is able to start another countdown.

I have not tested this extensively, but it should work fine

If you have any other problems/issues with this, feel free to ask!

Here is the file:

battlebus.rbxl (18.3 KB)

18 Likes

I think it’s also important to mention the TeleportPartyAsync (https://developer.roblox.com/en-us/api-reference/function/TeleportService/TeleportPartyAsync) as well. If you do not need or want the player’s to end up in a private instance but you still want the to all teleport together (like at the end of a round and returning to a lobby), you can use that function. Calling it is also more simple that using a reserved server.

2 Likes