How can i make teleporter part between places

I want to achive teleporter part with error handle

I tried this local script inside part

local Player = game.Players.LocalPlayer
local TeleportService = game:GetService("TeleportService")
local TARGET_PLACE_ID = 10543893394
local ServerScriptService = game:GetService("ServerScriptService")
local teleportGui = game:GetService("ReplicatedStorage")["TeleportGuiLvl0.001"]

local function handleFailedTeleport(player, teleportResult, errorMessage, targetPlaceId, teleportOptions)
	if teleportResult == Enum.TeleportResult.Flooded or teleportResult == Enum.TeleportResult.Failure then
		-- pause and retry if it's a one-time hiccup
		task.wait(2)
		-- teleportOptions automatically have the reservedServerCode filled up
		TeleportService:Teleport(TARGET_PLACE_ID, Player, teleportOptions)
	else
		-- throw an error if something else is wrong
		error(("Invalid teleport [%s]: %s"):format(teleportResult.Name, errorMessage))
	end
end

TeleportService.TeleportInitFailed:Connect(handleFailedTeleport)

local function Teleport()
	wait(2)
	TeleportService:SetTeleportGui(teleportGui)
	TeleportService:Teleport(TARGET_PLACE_ID, Player) 
	TeleportService.TeleportInitFailed:Connect(handleFailedTeleport)	
end

script.Parent.Touched:Connect(Teleport)
2 Likes

Put a server script inside the part with this code in:

local TS = game:GetService("TeleportService")

local placeID = your place ID

script.Parent.Touched:Connect(function(player)
	
	wait(0.5)
	TS:Teleport(placeID, player)
	
end)

I’m pretty sure LocalScripts don’t work in Workspace unless they are descendant of a player’s model.

You also have to send an array of player(s) instead of just sending the player object:

TeleportService:Teleport(TARGET_PLACE_ID, {Player}, teleportOptions)

and

TeleportService:Teleport(TARGET_PLACE_ID, {Player}) 

also I don’t think TeleportService doesn’t work in the client in the first place so change it to a script and make sure the part that is touching is a part of the player’s character model and you only have to connect handleFailedTeleport to TeleportService.TeleportInitFailed once:

local function handleFailedTeleport(player, teleportResult, errorMessage, targetPlaceId, teleportOptions)
	if teleportResult == Enum.TeleportResult.Flooded or teleportResult == Enum.TeleportResult.Failure then
		-- pause and retry if it's a one-time hiccup
		task.wait(2)
		-- teleportOptions automatically have the reservedServerCode filled up
		TeleportService:Teleport(TARGET_PLACE_ID, {player}, teleportOptions)
	else
		-- throw an error if something else is wrong
		error(("Invalid teleport [%s]: %s"):format(teleportResult.Name, errorMessage))
	end
end

TeleportService.TeleportInitFailed:Connect(handleFailedTeleport)	

local function Teleport(part)
    local player = game.Players:GetPlayerFromCharacter(part.Parent)
	
    if player ~= nil then
        task.wait(2)
	    TeleportService:SetTeleportGui(teleportGui)
	    TeleportService:Teleport(TARGET_PLACE_ID, {player})
    end
end

script.Parent.Touched:Connect(Teleport)
1 Like

This doesn’t work.


video:

local TeleportService = game:GetService("TeleportService")
local TARGET_PLACE_ID = 10543893394
local ServerScriptService = game:GetService("ServerScriptService")
local teleportGui = game:GetService("ReplicatedStorage")["TeleportGuiLvl0.001"]

local function handleFailedTeleport(player, teleportResult, errorMessage, targetPlaceId, teleportOptions)
	if teleportResult == Enum.TeleportResult.Flooded or teleportResult == Enum.TeleportResult.Failure then
		-- pause and retry if it's a one-time hiccup
		task.wait(2)
		-- teleportOptions automatically have the reservedServerCode filled up
		TeleportService:Teleport(TARGET_PLACE_ID, {player}, teleportOptions)
	else
		-- throw an error if something else is wrong
		error(("Invalid teleport [%s]: %s"):format(teleportResult.Name, errorMessage))
	end
end

TeleportService.TeleportInitFailed:Connect(handleFailedTeleport)	

local function Teleport(part)
	local player = game.Players:GetPlayerFromCharacter(part.Parent)

	if player ~= nil then
		wait(2)
		TeleportService:SetTeleportGui(teleportGui)
		TeleportService:Teleport(TARGET_PLACE_ID, {player})
	end
end

TeleportService.TeleportInitFailed:Connect(handleFailedTeleport)

Oh yeah, TeleportService also doesn’t work in studio so you have to publish it and test it in game.

1 Like

I tested it in game(check video)

At the very bottom line, TeleportService.TeleportInitFailed:Connect(handleFailedTeleport) is supposed to be script.Parent.Touched:Connect(Teleport), I accidentally posted that line twice in the original reply, sorry.

1 Like

Its work, thank you so much!!!

TeleportService:Teleport only takes a single player instance, it’ll implicitly receive the local player if called from a local script.

https://developer.roblox.com/en-us/api-reference/function/TeleportService/Teleport