Will this solution work for teleporting instead of TeleportInitFailed?

Greetings! I find .TeleportInitFailed a time consuming process of handling failed teleports, so I created my own solution:

while true do
	local Success, Error = pcall(function()
		TeleportService:TeleportAsync(_G.RaceGameID, TeleportingTable, TeleportOptions) -- Dev Beta: 9130693906 - Public Beta: 9050941346
	end)
	if Success then
		break
	else
		for _, Player in TeleportingTable do
			ReplicatedStorage.PopupKit.ShowNotification:FireClient(Player, "Teleport Failed", "", "TeleportService failed to teleport you to the game. Retrying...", "⚠️", Color3.fromRGB(31, 40, 255))
		end
	end
end

Will my solution possible be a better way of handling failed teleports?

Thanks in advance!

Looks like it should work because an article on the Developer wiki uses pcall on TeleportAsync, though they return the result, so you may have to do that as well.

Though I still recommend to use TeleportInitFailed in conjuction as you’ll be able to easily tell why the teleport couldn’t work, such as if too many teleports have been made or if the game was full or they’re already being teleported. This information can help you know when it’s best to teleport again, such as waiting 30 seconds before trying again if too many teleports happened (Flooded), or to not do another teleport if the game is full.

Try reading the article I linked to get an idea of how you can use TeleportInitFailed for safer teleporting

1 Like

I don’t really care about that lol. I just want it to work. Also, I am using ReservedServers so as long as I am not dumb and change the Max Player Count to anything below 8, I should be fine lol.

And yes, I will fix the _G.

If you believe that it’ll work without the need of TeleportInitFailed, then you simply just need to return the TeleportAsyncFailed for it to work well with pcalling,

while true do
	local Success, Error = pcall(function()
		return TeleportService:TeleportAsync(_G.RaceGameID, TeleportingTable, TeleportOptions) -- Dev Beta: 9130693906 - Public Beta: 9050941346
	end)
	if Success then
		break
	else
		for _, Player in TeleportingTable do
			ReplicatedStorage.PopupKit.ShowNotification:FireClient(Player, "Teleport Failed", "", "TeleportService failed to teleport you to the game. Retrying...", "⚠️", Color3.fromRGB(31, 40, 255))
		end
	end
end

Make sure to add some retrying in this code as well

1 Like