How to create new place for teleport?

I want to know how you would create a new place for a group of players to teleport to. The best example of this is like in TDS (Tower Defense Simulator), where you go down the elevator and teleport to a new place with only those players in the elevator. I want to do the exact same thing but for my game.

I already know how to use teleport service but it teleports all the players to the same place. I want a new place for every group of players.

You cant get “a new place for every group of players”, what you can do is make a reserved server and then put all the players you want to teleport inside of a table, and just teleport the players from the table to a reserved server. Example code:

local players = {} -- add players to the players table how you want
local placeId = YOUR_PLACE_ID_HERE
local reservedServer = game.TeleportService:ReserveServer(placeId)
game.TeleportServiceTeleportToPrivateServer(placeId, reservedServer, players)

If you want to add the players to the table when they touch a part just do this in the same script above the teleport function but below the players table, example:

local players = {} -- add players to the players table how you want
local placeId = YOUR_PLACE_ID_HERE
local Part = script.Parent -- or the location to the part thats gonna be touched.
Part.Touched:Connect(function(hit)
     pcall(function()
        local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
        table.insert(players, plr
    end)
end)
task.wait(intermissionTime) -- this can be how long you want to wait until you teleport everyone
local reservedServer = game.TeleportService:ReserveServer(placeId)
game.TeleportServiceTeleportToPrivateServer(placeId, reservedServer, players)
3 Likes

Would the place id be the id I find in the URL of my game page or the id I find in the places folder in studio?

Yes, an example place id: 185655149 (a place id of the default place of an experience)

OR

If you created a new place in the same experience, you would copy that placeID using the roblox studio Asset Manager > Places find the place and right click on it and click on Copy Id

Would I only have to make one place for all the different groups of players? Or would I have to duplicate a few?

You would have to make only one place. An example of more places would be:

  • A game where you cant store everything in one place or dont want to (example a murder mystery game or similar):
    • A lobby place (the default one where everyone spawns and teleports to the game)
    • The game/round place (the place where most of the stuff happens)
    • Additional places (a tutorial place or something else)

There is an error on line 11 for the script where you touch the part. Do you know what’s wrong?

Error: TeleportService is not a valid member of DataModel “Game”

Replace Game with game. Its case sensitive.

I have edited your script a little bit but now I have another problem.

Script:

local players = {} – add players to the players table how you want

local placeId = MY_PLACE_ID

local Part = script.Parent – or the location to the part thats gonna be touched.

local TeleportService = game:GetService(“TeleportService”)

Part.Touched:Connect(function(hit)

pcall(function()

local plr = game.Players:GetPlayerFromCharacter(hit.Parent)

table.insert(players, plr)

end)

end)

wait()

local reservedServer = TeleportService:ReserveServer(placeId)

TeleportService:TeleportToPrivateServer(placeId, reservedServer, players)

On the last line, it doesn’t work. I don’t really know why.

What do you mean it doesnt work? Is it not teleporting or?

Note: You can NOT teleport players inside of roblox studio, so publish the game and test it in real roblox and not in studio. And you can only teleport from a place you own to a place you also own.

I have been doing it in the actual game. Do you want me to send you the error?

Yes, that would help a lot if I had the error

TeleportService::TeleportToPrivateServer must be passed an array of players

Try putting the teleport in a pcall, and wait a couple of seconds so you can load in and actually touch the part.

local players = {}

local placeId = 7951878865

local Part = script.Parent 

local TeleportService = game:GetService("TeleportService")

Part.Touched:Connect(function(hit)
	pcall(function()
		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		if (plr:IsA("Player")) then
           table.insert(players, plr)
        end
	end)
end)

task.wait(10)
print("teleporting")
print(players)

pcall(function()
	local reservedServer = TeleportService:ReserveServer(placeId)
	TeleportService:TeleportToPrivateServer(placeId, reservedServer, players, nil, nil, nil)
end)

Same error again! I don’t know what to do.

I edited the code, try it again, also are you touching the part in the 10 second time frame?

Made another edit, this time i checked if the player is a player instance.

Still the same error! Do you know anyone else that might have more knowledge on this topic?

I added a print to the code, can you tell me what does it print?


This is what I is telling me.