Although I put it in a pcall(), if the teleport fails, it doesn’t return anything.
RemoteFunction:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TeleportService = game:GetService("TeleportService")
ReplicatedStorage.TeleportationSystem.OnServerInvoke = function(player,ID)
print(player.Name,ID)
local success,fail = pcall(function()
TeleportService:Teleport(ID,player)
end)
if not success then
return false
end
end
StarterGui:
ReplicatedStorage.RealmSystem.OnClientEvent:Connect(function(RealmID)
if Teleport == false then
Teleport = true
FadeInBackground:Play()
FadeInBackground.Completed:Wait()
SizeOutLogo:Play()
SizeOutLogo.Completed:Wait()
local result = ReplicatedStorage:FindFirstChild("TeleportationSystem"):InvokeServer(RealmID)
if result == false then
SizeInLogo:Play()
SizeInLogo.Completed:Wait()
FadeOutBackground:Play()
FadeOutBackground.Completed:Wait()
end
end
end)
TeleportService.TeleportInitFailed:Connect(function(player, teleportResult, errorMessage)
if player == localPlayer then
print("Teleport failed, TeleportResult: "..teleportResult.Name)
-- check the teleportResult to ensure it is appropriate to retry
if teleportResult == Enum.TeleportResult.Failiure or teleportResult == Enum.TeleportResult.Flooded then
-- disconnect the connection
-- retry in retryTime seconds
delay(retryTime, function()
print("Reattempting teleport")
TeleportService:Teleport(placeId)
end)
end
end
end)
The code works if it doesn’t return anything to the client. In this case, where it says print(), it will actually work perfectly in a server if that happens. Example:
ReplicatedStorage.TeleportationSystem.OnServerInvoke = function(player,ID)
local connection
connection = TeleportService.TeleportInitFailed:Connect(function(player, teleportResult, errorMessage)
if player == player then
print("Teleport failed, TeleportResult: "..teleportResult.Name)
if teleportResult == Enum.TeleportResult.Failure or teleportResult == Enum.TeleportResult.Flooded then
connection:Disconnect()
end
end
end)
TeleportService:Teleport(ID,player)
end
However, I’m not sure as to how to return a false value to the client since it’s a RemoteFunction.
I got to here and it still won’t send anything back. Any ideas?
ReplicatedStorage.TeleportationSystem.OnServerInvoke = function(player,ID)
local connection
local result
connection = TeleportService.TeleportInitFailed:Connect(function(player, teleportResult, errorMessage)
if player == player then
print("Teleport failed, TeleportResult: "..teleportResult.Name)
if teleportResult == Enum.TeleportResult.Failure or teleportResult == Enum.TeleportResult.Flooded then
result = false
connection:Disconnect()
end
end
end)
TeleportService:Teleport(ID,player)
return result
end