TeleportFailed - Previous teleport is in processing (IsTeleporting)

Is there a way to stop the teleport or, if not, how long does the IsTeleporting last so I can do a timeout?

Current code:

game.Workspace.SystemEvents.RealmSystem.OnClientEvent:Connect(function(ID)
	if Teleport == false then
		Teleport = true
		--Tween UI
		FadeInBackground:Play()
		FadeInBackground.Completed:Wait()
		SizeOutLogo:Play()
		SizeOutLogo.Completed:Wait()
		--Teleport system
		TeleportService:SetTeleportGui(TeleportUI)
		local teleportOptions = Instance.new("TeleportOptions")
		local teleportData = {
			placeId = game.PlaceId,
			jobId = game.JobId
		}
		teleportOptions:SetTeleportData(teleportData)
		local connection
			connection = TeleportService.TeleportInitFailed:Connect(function(player, teleportResult, errorMessage)
				if player == game.Players.LocalPlayer then
				IssueTPError()
				connection:Disconnect()
				end
			end)
		TeleportService:Teleport(ID, game.Players.LocalPlayer, teleportOptions)
	end
end)
1 Like

I don’t think there is a way to stop a teleport, and I don’t have the exact time, but I think it is like a few secs.

I don’t think it is cause I even put a timeout at 15 seconds and it still says IsTeleporting; it’s basically disrupting other teleports. :rofl:

1 Like

Well, are you trying to teleport to the same place, more then one time?

Because what I can see from the error message, you are trying to teleport someone, then you try to teleport them again, that’s why it says (IsTeleporting)

1 Like

No; it runs once and then, if there’s an error, it does IssueTPError() which sets the Teleport variable to false to use as a cooldown for, in this case, 15 seconds. After 15 seconds, the person can initiate the teleport again manually.

I also disconnected the function for TeleportInitFailed - it doesn’t repeat on retry. So the IsTeleporting bit is the only issue.

After some looking, I can not find a way to see if a player “IsTeleporting”, sorry If I can’t help you.

1 Like

Let me pull up the smaller bit of code if that helps.

RemoteEvent for realm portals in Workspace:

Realms = game.Workspace.Realms:GetChildren()
ReplicatedStorage = game:GetService("ReplicatedStorage")

RealmIDs = {
	["RealmTest"] = 8483996488;
	["MainGame"] = 8443566372;
	["FakeGame"] = 1
}

function GetRealmMatch(Realm)
	
	for realm,id in pairs(RealmIDs) do
		if realm == Realm then
			return id
		end
	end
end

for i,realmteleporter in pairs(Realms) do
	if realmteleporter.ClassName == "Part" then
		realmteleporter.Touched:Connect(function(hit)
			local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
			if player then
				local RealmID = GetRealmMatch(realmteleporter.Name)
				game.Workspace.SystemEvents:FindFirstChild("RealmSystem"):FireClient(player,tonumber(RealmID))
			end
		end)
	end
end

StarterGui:

UI.TPError.Base.Okay.Activated:Connect(function()
	UI.TPError.Base:TweenPosition(UDim2.new(0, 0, 1, 0), 'Out', 'Quart', 0.75, true)
	FadeOut:Play()
	ErrorOpen = false
end)

function IssueTPError()
	SizeInLogo:Play()
	SizeInLogo.Completed:Wait()
	FadeOutBackground:Play()
	FadeOutBackground.Completed:Wait()
	ErrorOpen = true
	UI.TPError.Base:TweenPosition(UDim2.new(0, 0, 0, 0), 'Out', 'Quart', 0.75, true)
	FadeIn:Play()
	local timeremaining = 15
	while timeremaining > 0 do
		UI.TPError.Base.Countdown.Text = "Servers are currently overloaded. Try again in "..timeremaining.." seconds."
		timeremaining -= 1
		wait(1)
	end
	Teleport = false
	if ErrorOpen == true then
		UI.TPError.Base:TweenPosition(UDim2.new(0, 0, 1, 0), 'Out', 'Quart', 0.75, true)
		FadeOut:Play()
		ErrorOpen = false
	end
end

game.Workspace.SystemEvents.RealmSystem.OnClientEvent:Connect(function(ID)
	if Teleport == false then
		Teleport = true
		--Tween UI
		FadeInBackground:Play()
		FadeInBackground.Completed:Wait()
		SizeOutLogo:Play()
		SizeOutLogo.Completed:Wait()
		--Teleport system
		TeleportService:SetTeleportGui(TeleportUI)
		local teleportOptions = Instance.new("TeleportOptions")
		local teleportData = {
			placeId = game.PlaceId,
			jobId = game.JobId
		}
		teleportOptions:SetTeleportData(teleportData)
		local connection
			connection = TeleportService.TeleportInitFailed:Connect(function(player)
				if player == game.Players.LocalPlayer then
				IssueTPError()
				connection:Disconnect()
				end
			end)
		TeleportService:Teleport(ID, game.Players.LocalPlayer, teleportOptions)
	end
end)

I am confused…

Why does the error even happen.

The only way I can think this is happening it that it try’s to teleport this player more then 1 time.

In the first script, you have this:

This is no built in delay, so if more then one part of the player hit this, then it will try and teleport the player more then one time.

That is the only reason I can think of.

1 Like

I could try and patch that up right now, but I don’t see a reason as to why it would do it cause, although it spams the event, if the cooldown isn’t off, they’re not going through.

However, I do agree that it is bad practice.

After a few secs, then you put the delay off, so if it does fail, then they can try again.

1 Like

Yeah, you’re actually right. I’ll go fix that up right now and we’ll see if that does the trick.

Sounds good :slight_smile:

If you need any help puting it in, but ask :slight_smile:

So, I did what you said and it seems that it’s still unchanged.

Here’s the code of the touch script:

Realms = game.Workspace.Realms:GetChildren()
ReplicatedStorage = game:GetService("ReplicatedStorage")
Cooldown = false

RealmIDs = {
	["RealmTest"] = 8483996488;
	["MainGame"] = 8443566372;
	["FakeTest"] = 1
}

function GetRealmMatch(Realm)
	for realm,id in pairs(RealmIDs) do
		if realm == Realm then
			return id
		end
	end
end

for i,realmteleporter in pairs(Realms) do
	if realmteleporter.ClassName == "Part" then
		realmteleporter.Touched:Connect(function(hit)
			if Cooldown == false then
				Cooldown = true
				local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
				if player then
					local RealmID = GetRealmMatch(realmteleporter.Name)
					game.Workspace.SystemEvents:FindFirstChild("RealmSystem"):FireClient(player,tonumber(RealmID))
				end
				wait(5)
			end
			Cooldown = false
		end)
	end
end

As you can see, it requires the cooldown to be off, so that’s practically 1 touch per 5 seconds (if I did it right).
Let me try doing a print() inside and see if that’ll give us more clues.

Update: Seems that the cooldown that I added in is not working at all. Do you have an idea where I could put it?

Ok, you need to make it so there is a table, where all players are, and give all the players in that table a cooldown bool (like true, or false) and if then try to go though the portal, it will put the delay on, after a few secs, it turns off.

What you have done is make it so if anyone trys to go into the portal, no one can go into the portal until the cooldown is done.

Alright, I’ll try that. Just a second.

Update: Did something else (I’ll just polish it like you said later, I just need the functionality right now). Let me test it real quick.

Nope; I ran the event twice through the console, the first time being the unreachable place and the other being the normal place. As soon as it can’t teleport once, anything behind that will also follow the same pattern.

Really clueless as to what to do. So it’s not the code from Workspace, it’s something inside of the OnClientEvent function.