PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

OnTeleport

Fired when the TeleportState of a player changes. This event is useful for detecting whether a teleportation was successful.

What is the TeleportState?

When a teleportation request is made using TeleportService, there are a series of stages before the Player is teleported. The current stage is represented by the Enum/TeleportState value which is given by OnTeleport. See below for a practical example of this.

Parameters

Name Type Default Description

The new Enum/TeleportState of the Player.

The ID of the place the Player is being teleported to.

The name of the spawn to teleport to, if TeleportService/TeleportToSpawnByName has been used.


Code Samples


Player.OnTeleport

This example prints which stage of a teleport a player is at, as well as printing if the teleport was a failure.

game.Players.PlayerAdded:Connect(function(player)
	local playerOnTeleport = player
	player.OnTeleport:Connect(function(teleportState, placeId, spawnName)
		if teleportState == Enum.TeleportState.Started then
			print("Teleport started ("..playerOnTeleport.Name..")")
		elseif teleportState == Enum.TeleportState.WaitingForServer then
			print("Teleport waiting for server ("..playerOnTeleport.Name..")")
		elseif teleportState == Enum.TeleportState.InProgress then
			print("Teleport in progress ("..playerOnTeleport.Name..")")
		elseif teleportState == Enum.TeleportState.Failed then
			print("Teleport failed! ("..playerOnTeleport.Name..")")
		end
	end)
end)