Issue - How to check if Game Teleport failed?

Although I put it in a pcall(), if the teleport fails, it doesn’t return anything.

RemoteFunction:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TeleportService = game:GetService("TeleportService")

ReplicatedStorage.TeleportationSystem.OnServerInvoke = function(player,ID)
    print(player.Name,ID)
    local success,fail = pcall(function()
        TeleportService:Teleport(ID,player)
    end)
    if not success then
        return false
    end
end

StarterGui:

ReplicatedStorage.RealmSystem.OnClientEvent:Connect(function(RealmID)
    if Teleport == false then
        Teleport = true
        FadeInBackground:Play()
        FadeInBackground.Completed:Wait()
        SizeOutLogo:Play()
        SizeOutLogo.Completed:Wait()
        local result = ReplicatedStorage:FindFirstChild("TeleportationSystem"):InvokeServer(RealmID)
        if result == false then
            SizeInLogo:Play()
            SizeInLogo.Completed:Wait()
            FadeOutBackground:Play()
            FadeOutBackground.Completed:Wait()
        end
    end
end)

TeleportService.TeleportInitFailed
More info here: TeleportService | Roblox Creator Documentation

1 Like

I’ll take a look into that. Will update.

 TeleportService.TeleportInitFailed:Connect(function(player, teleportResult, errorMessage)
        if player == localPlayer then
            print("Teleport failed, TeleportResult: "..teleportResult.Name)
            -- check the teleportResult to ensure it is appropriate to retry
            if teleportResult == Enum.TeleportResult.Failiure or teleportResult == Enum.TeleportResult.Flooded then
                -- disconnect the connection
 
                -- retry in retryTime seconds
                delay(retryTime, function()
                    print("Reattempting teleport")
                    TeleportService:Teleport(placeId)
                end)
            end
        end
    end)

from devhub

So, here’s where it stands:

The code works if it doesn’t return anything to the client. In this case, where it says print(), it will actually work perfectly in a server if that happens. Example:

ReplicatedStorage.TeleportationSystem.OnServerInvoke = function(player,ID)
	local connection
	connection = TeleportService.TeleportInitFailed:Connect(function(player, teleportResult, errorMessage)
		if player == player then
			print("Teleport failed, TeleportResult: "..teleportResult.Name)
			if teleportResult == Enum.TeleportResult.Failure or teleportResult == Enum.TeleportResult.Flooded then
				connection:Disconnect()
			end
		end
	end)
	TeleportService:Teleport(ID,player)
end

image

However, I’m not sure as to how to return a false value to the client since it’s a RemoteFunction.

I got to here and it still won’t send anything back. Any ideas?

ReplicatedStorage.TeleportationSystem.OnServerInvoke = function(player,ID)
	local connection
	local result
	connection = TeleportService.TeleportInitFailed:Connect(function(player, teleportResult, errorMessage)
		if player == player then
			print("Teleport failed, TeleportResult: "..teleportResult.Name)
			if teleportResult == Enum.TeleportResult.Failure or teleportResult == Enum.TeleportResult.Flooded then
				result = false
				connection:Disconnect()
			end
		end
	end)
	TeleportService:Teleport(ID,player)
	return result
end

Still not resolved, any ideas are appreciated!

Still haven’t resolved the issue; tried various ideas, but it’s not returning anything. My hands are tied.

Any feedback is appreciated.