How to check if player left during teleport

I am trying to have a create server function which all works, but I noticed if the player leaves after the server gets created it breaks some things.

I want to check if the play successfully made it to the game, and if not, run the deleteserver() function

Heres what I have

code = TeleportService:ReserveServer(15591987221)
local playertable = {}
		playertable[1] = player
		local suc,eor = pcall(function()
		TeleportService:TeleportToPrivateServer(15591987221,code,playertable)
		end)
		if eor then
			deleteserver(code)
			task.wait()
			return
		else 
			if not player.PlayerGui:FindFirstChild("joinsound") then
				local snd = script.joinsound:Clone()
				snd.Parent = player.PlayerGui
				snd.Enabled = true
			end
		end

Try changing if eor then to if not suc then

I have tried that, I have my node js console pulled up ( it will print if the server is getting removed ), and I forcefully quit roblox right before it teleports me, the js server console doesn’t show that it is removing, and it only showed that it created the server.

code = TeleportService:ReserveServer(15591987221)
teleportdata:SetAsync(tostring(player.UserId),sdata,60)
		local playertable = {}
		playertable[1] = player
		local suc,eor = pcall(function()
		TeleportService:TeleportToPrivateServer(15591987221,code,playertable)
		end)
		if not suc then
			deleteserver(code)
			task.wait()
			return
		else 
			if not player.PlayerGui:FindFirstChild("joinsound") then
				local snd = script.joinsound:Clone()
				snd.Parent = player.PlayerGui
				snd.Enabled = true
			end
		end

I think you would have to use MemoryStoreService for this. MemoryStoreService can be accessed by any server in the experience, and is also temporary (unlike Data Stores), which is good because you don’t need to worry about cleanup.

local MemoryStoreService = game:GetService("MemoryStoreService")
local HashMap = MemoryStoreService:GetHashMap("AnyName")
local Result = TeleportService:TeleportAsync(...) -- Returns a TeleportAsyncResult object
local UserList = {} -- List of UserId's

-- First parameter is the key to the entry. PrivateServerId is unique and can also be accessed by game.PrivateServerId
HashMap:SetAsync(Result.PrivateServerId, UserList, ExpirationTime) -- Wrap this in a pcall. 

Since PrivateServerId can be accessed from both servers (start and destination), it should be used as the key. In the destination-server, the HashMap can be read from, like so:

local Result = HashMap:GetAsync(game.PrivateServerId) -- Should return a list of UserId's

for _, UserId in Result do
	for _, Player in Players:GetPlayers() do
		if Player.UserId == UserId then continue end
	end

	-- A player that was originally teleported is no longer in the game.
	-- Make sure the player didn't leave AFTER he was teleported to the new server.
	-- Close the server from here.
end

This wouldn’t be checked instantly, as it might take a little while for all players to enter the game correctly.

As far as I know, there is no “correct” way to detect if a player has left the game during teleportation, but if there is, please correct me. Regarding the code, it’s obviously simplified, so make sure to always follow best practices: