How can I tell if a Teleport failed?

Hello, I am trying to make an Admin panel that can teleport the admin to whatever server a player is in, the issue is I cant tell if the teleport failed or not. If it fails it end up messing the TeleportService for that player because it thinks the player is still teleporting. How can I cancel a failed teleport too?

Also is there a way to tell if the player is in a reserved server or just a public one?

1 Like

I would use a pcall to catch the error (and possibly even send a warning to the player that their teleport failed).

There are a couple topics that already ask and answer this question, here are some examples to get you started:

Hope this helps!

(Edit: Not sure, but when a teleport fails, does it throw an error or not? If not, pcall won’t work.)

I already have a Pcall set up, and the teleport failed screen like this does not get caught:

Edit: I am also trying to tell what kind of server the player is in without physically being in their server. So if they are in a Reserved Server I would need to use a different teleport function than if they are in a Public Server.

I looked through the TeleportService documentation a little more, and apparently there is a TeleportInitFailed event that fires on both the server and client when a player fails to teleport.

When teleporting a player to a server, you must have created the server in the first place, right? Or is that not how this works?

Yes, so I need to give some more context on whats going on and what im trying to achieve. The game works on a Lobby system that players join and then teleport somewhere. I am making an admin panel to where all the admin has to do is type in the players name and then they are able to join them. The issue is I dont know how to tell if the target player is in a reserved server or a private server. If the player is in a reserve server it requires a special teleport which is why im getting the teleport failed error I sent. I can look into the teleportintfailed to see what I can make of that.

If you’re able to get the ID of the server you are trying to teleport to (I assume you can), you can use the method listed below to try and determine the server type:

Yea but that will only work if im in the same server, not if im in a different server.

You could use MessagingService to send a request to the player’s server and return the server type.

This would work

local TeleportService = game:GetService("TeleportService")

local function teleportPlayer(adminPlayer, targetPlayer)
    local success, teleportResult = pcall(function()
        return TeleportService:TeleportToPlaceInstance(targetPlayer.GameId, targetPlayer.PlaceId, adminPlayer)

    if not success then
        -- if the teleport failed, cancel the teleport for the admin player
        warn("Teleport failed for player "..adminPlayer.Name)
        print("Teleport successful for player "..adminPlayer.Name)

He tried using a pcall and this error would still pop up:

This will probably work, I will update when I am able to test this.

1 Like