Server Script does not run after TeleportAsync

Good morning. Buenos días.

In the top of my script, I have warn("Ad"), and upon joining the game it runs successfully.

Now upon using TeleportAsync, nothing pops up in the server tab of output.

local teleportOptions = Instance.new("TeleportOptions")
			teleportOptions:SetTeleportData({
				["earned"] = money[plr],
				["nonce"] = HttpService:GenerateGUID(false):lower()
			})
			
			local function TeleportPlayer(player)
				local success, errorMessage = pcall(function()
					TeleportService:TeleportAsync(placeId, {player}, teleportOptions)
				end)

				if not success then
					wait(2)
					
					TeleportPlayer(player)
				end
			end
			
			TeleportPlayer(Players:GetPlayers()[1])

Oddly enough, being teleported a second time (to the third game) runs it successfully. So what’s the issue?

Your function is recursive so if the success variable is repeatedly false then your function will run for an eternity not allowing the code below to run. You should have a retry system instead where if you reach the max amount of tries you stop trying to teleport the player

1 Like

I will keep that noted! However most of the time it returns as a success which doesn’t affect the main script much

Do you think I should make the client wait for a few seconds, since I have a RemoteFunction telling the server to start the action?

(I’ve already tried this, I don’t think the server loads at all)

I found the solution:

I was teleported to the original server, thus why it seemed like it wasn’t running; it already ran.

I just used ReserveServer and TeleportToPrivateServer.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.