# TeleportOptions

TeleportOptions : `Instance`

## Overview

`TeleportService:TeleportAsync()` 호출 시 함께 전달하여 플레이어를 어떤 서버로 텔레포트시킬지 세부 동작을 지정하는 옵션 인스턴스입니다.&#x20;

예약 서버의 접근 코드, 특정 서버 인스턴스 ID 지정, 새로운 서버를 예약할지 여부 등을 설정할 수 있으며, 각 옵션은 동시에 사용할 수 없는 조합이 있으므로 아래 속성 설명을 참고하여 한 가지 방식으로만 지정해야 합니다.

## Properties

### ReservedServerAccessCode

`string`

텔레포트할 예약 서버를 가리키는 접근 코드(Access Code)를 지정하는 속성입니다.&#x20;

`TeleportService:ReserveServer()` 등을 통해 미리 예약된 서버의 접근 코드를 이 속성에 설정하면, 해당 서버로 플레이어들을 텔레포트시킬 수 있습니다.

`ServerInstanceId`와 동시에 지정할 수 없으며, `ShouldReserveServer`가 `true`인 경우에는 반드시 비어 있어야 합니다.

#### Code Samples

```lua
local TeleportService = game:GetService("TeleportService")

local targetPlaceId = 1234 -- 월드에 연결된 Place의 Id

-- 전용 서버 생성
local success, errorOrAccessCode = pcall(function()
    return TeleportService:ReserveServerAsync(targetPlaceId)
end)

if not success or errorOrAccessCode == nil or errorOrAccessCode == "" then
    return
end

-- TeleportOptions 설정
local options = Instance.new("TeleportOptions")	
options.ReservedServerAccessCode = errorOrAccessCode -- 예약 서버 접근 코드
options.ShouldReserveServer = false                  -- 새로운 예약 서버 생성 여부 (ReservedServerAccessCode 사용시 false여야 합니다.)

-- 텔레포트 실행
local success, errorOrResult = pcall(function()
    local players = { player } -- 텔레포트할 플레이어 목록
		
    local teleportResult = TeleportService:TeleportAsync(targetPlaceId, players, options)     
    return teleportResult
end)

print("TeleportAsyncResult.ReservedServerAccessCode : ", errorOrResult.ReservedServerAccessCode)
```

### ServerInstanceId

`string`

플레이어들을 텔레포트시킬 대상 서버 인스턴스의 ID를 지정하는 속성입니다. 이미 실행 중인 특정 서버 인스턴스로 보내고 싶을 때 해당 서버 인스턴스 ID를 설정합니다.

`ReservedServerAccessCode`와 동시에 지정할 수 없으며, `ShouldReserveServer`가 `true`인 경우에는 반드시 비어 있어야 합니다.

#### Code Samples

```lua
local TeleportService = game:GetService("TeleportService")
local DataStoreService = game:GetService("DataStoreService") 
local SessionStore = DataStoreService:GetDataStore("PlayerPrevSessionId")

-- 저장된 이전 세션 Id 가져오기
local jobId = nil
local success, errorOrLoadValue = pcall(function()
    return SessionStore:GetAsync(player.UserId)
end) 

if not success or errorOrLoadValue == nil then
    return
end
jobId = errorOrLoadValue 

-- TeleportOptions 설정
local options = Instance.new("TeleportOptions")	
options.ServerInstanceId = jobId    -- 특정 공개 서버로 입장(game.JobId 값 전달)
options.ShouldReserveServer = false -- 새로운 예약 서버 생성 여부 (ServerInstanceId 사용시 false여야 합니다.)

-- 텔레포트 실행
local success, errorOrResult = pcall(function()
    local targetPlaceId = 1234 -- 월드에 연결된 Place의 Id
    local players = { player } -- 텔레포트할 플레이어 목록
		
    local teleportResult = TeleportService:TeleportAsync(targetPlaceId, players, options)     
    return teleportResult
end)
```

### ShouldReserveServer

`boolean`

텔레포트 요청 시 새로운 서버를 예약하여 그 서버로 보낼지 여부를 지정하는 속성입니다. `true`로 설정하면 텔레포트 요청과 함께 서버를 새로 예약하며, 이 경우 `ReservedServerAccessCode`와 `ServerInstanceId`는 모두 비어 있어야 합니다.

기본값은 `false`입니다.

#### Code Samples

```lua
local TeleportService = game:GetService("TeleportService")

-- TeleportOptions 설정
local options = Instance.new("TeleportOptions")	
options.ShouldReserveServer = true -- 새로운 예약 서버 생성 여부

-- 텔레포트 실행
local success, errorOrResult = pcall(function()
    local targetPlaceId = 1234 -- 월드에 연결된 Place의 Id
    local players = { player } -- 텔레포트할 플레이어 목록
		
    local teleportResult = TeleportService:TeleportAsync(targetPlaceId, players, options)     
    return teleportResult
end)
```

## Methods

## Events

## See also

{% content-ref url="/pages/IJpK8Xy2OodL1R6Kcf7g" %}
[Place & Teleport](/korean/manual/studio-manual/game-development/place-and-teleport.md)
{% endcontent-ref %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.overdare.com/korean/development/api-reference/classes/teleportoptions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
