Teleport to a new server

I’ve got a game where players can either join a new match every 5 minute or join an existing match.

For joining a new match: When a match starts, I want to teleport them to another place and start a new server in that place, where the players will play. How can I code it out such that whenever my players are teleported to a specific placeId, they will be in a new server without any other players?

For joining an existing match: How can I check if the existing players in the server does not exceed the server capacity and then teleport the player to the specific server?

4 Likes

Use the TeleportService inside of ROBLOX.

Here is an example:

script.Parent.MouseButton1Down:connect(function()
    game:GetService("TeleportService"):Teleport(place id, game.Players.LocalPlayer) 
end)'

Heres another example for objects:


local TeleportService = game:GetService("TeleportService")
local placeID = place id

function onTouched(hit)
  local player = game.Players:GetPlayerFromCharacter(hit.Parent)
  if player then
       TeleportService:Teleport(placeID , player)
    end
end

script.Parent.Touched:connect(onTouched)

TeleportService:TeleportPartyAsync (roblox.com)

You need to add a table of players into the parameters of this function so the script recognizes each player and teleports all of them to the specified place.

1 Like

OOHH i didnt read the post title that much.

also i never knew about the TeleportPartyAsync.

so basically like this? (from the website)

local Players = game:GetService("Players")
local TeleportService = game:GetService("TeleportService")

local placeId = 0 -- replace
local playerList = Players:GetPlayers()

local success, result = pcall(function()
    return TeleportService:TeleportPartyAsync(placeId, playerList)
end)

if success then
   local jobId = result
   print("Players teleported to "..jobId)
  else
   warn(result)
end

thats pretty cool.

3 Likes

Yeah, that’s pretty much how it works. You just make a table with player objects, add them to the function and it will tp anyone in that table. It’s pretty handy for scenarios like if you wanted to make a planetory exploration game where specific players in a spaceship travel to a whole new planet.

2 Likes