PcoWSkbVqDnWTu_dm2ix

Teleporting Within a Place

Teleporting Within a Place

5 min

Teleporting a player’s character to a different coordinate point — while maintaining the character’s structural makeup — is achieved by moving the character’s Humanoid/RootPart|RootPart. This article outlines a module-based approach with adjustable parameters.

Teleport Module

Basic teleport functionality can be wrapped in a ModuleScript so that it can be called from other scripts.

  1. Create a new ModuleScript within ReplicatedStorage and rename it TeleportWithinPlace.
  1. Copy and paste in the following code:

Module Usage

Teleport on Part Touch

Teleportation can be easily triggered when a player touches a part such as a teleporation pad or an invisible trigger part at a door’s entry point.

  1. Include the Teleport Module in your project.
  2. Attach a Script to an anchored BasePart and paste in the code below.
  1. Adjust the variable values on lines 5–7 as desired:
Variable Description
TELEPORT_DESTINATION The datatype/Vector3 position to teleport the player to.
TELEPORT_FACE_ANGLE Angular direction character should face following teleportation, between -180 and 180.
FREEZE_CHARACTER Whether to temporarily "freeze" the character during teleportation, preventing movement or jumping.

Teleport on Client Action

Because player teleportation should only be called on the game server, you’ll need to fire a articles/Remote Functions and Events|remote event alongside client-side actions like activation of a GUI button. The following setup outlines this process.

  1. Make sure you’ve included the Teleport Module in your project.
  2. Add a new Script to ServerScriptService and paste in the code below — this gets the remote event created by the teleport module and, upon an RemoteEvent/OnServerEvent|OnServerEvent connection, finds the Humanoid associated with the player and calls the module’s Teleport function.
  1. Attach a LocalScript to a TextButton or ImageButton and paste in the following code:
  1. Adjust the variable values on lines 5–7 as desired:
Variable Description
TELEPORT_DESTINATION The datatype/Vector3 position to teleport the player to.
TELEPORT_FACE_ANGLE Angular direction character should face following teleportation, between -180 and 180.
FREEZE_CHARACTER Whether to temporarily "freeze" the character during teleportation, preventing movement or jumping.
Tags:
  • teleport
  • coding