-
What do you want to achieve? I want to teleport between places in my game on button click with error handle
-
What is the issue? It just doesn’t teleport me, doesn’t give me any errors
-
What solutions have you tried so far? I tried this
local pb = script.Parent.Play
local Player = game.Players.LocalPlayer
local TeleportService = game:GetService("TeleportService")
local TARGET_PLACE_ID = 10331222528
local ServerScriptService = game:GetService("ServerScriptService")
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:TeleportAsync(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 play() -- play button (level 0 teleport)
TeleportService:TeleportAsync(TARGET_PLACE_ID, Player)
TeleportService.TeleportInitFailed:Connect(handleFailedTeleport)
end
pb.MouseButton1Click:Connect(play)