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)
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)
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)
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)
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.