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)
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)
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.
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 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.
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.
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.
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.