Hey everyone, I really need suggestions, approaches on this topic, please help.
TeleportService
use to fail, with TeleportInitFailed
we can get that fail and retry.
What could I expect if the game is receiving thousands of players? I mean, each server will contain max 25 players, but, how reliable would be using a system like this (similar to the Roblox Hub example of SafeTeleport module (script at the bottom)) while most of those players will try to perform a teleport to another place, handled by SafeTeleport module.
-
If a player push a button on GUI, that triggers a RemoteEvent, Server handles the teleporting using the SafeTeleport module, there is a risk of
TeleportService
gets flooded? Maybe the entire server (25 players will perform the teleport, at different moments, or inmediately after join, they are not a group, they join at different times when joining game from website/app/deskApp) -
Whats the most reliable way you could suggest to handle any issue and get consistent teleports? Please I really need help with this, examples, experiences anyone had in the past, suggestions
Its extremely important that all those incoming players gets a succesful teleport…
This is the module in Roblox Hub about SafeTeleport, and I would be using a very similar approach:
local TeleportService = game:GetService("TeleportService")
local ATTEMPT_LIMIT = 5
local RETRY_DELAY = 1
local FLOOD_DELAY = 15
local function SafeTeleport(placeId, players, options)
local attemptIndex = 0
local success, result -- define pcall results outside of loop so results can be reported later on
repeat
success, result = pcall(function()
return TeleportService:TeleportAsync(placeId, players, options) -- teleport the user in a protected call to prevent erroring
end)
attemptIndex += 1
if not success then
task.wait(RETRY_DELAY)
end
until success or attemptIndex == ATTEMPT_LIMIT -- stop trying to teleport if call was successful, or if retry limit has been reached
if not success then
warn(result) -- print the failure reason to output
end
return success, result
end
local function handleFailedTeleport(player, teleportResult, errorMessage, targetPlaceId, teleportOptions)
if teleportResult == Enum.TeleportResult.Flooded then
task.wait(FLOOD_DELAY)
elseif teleportResult == Enum.TeleportResult.Failure then
task.wait(RETRY_DELAY)
else
-- if the teleport is invalid, report the error instead of retrying
error(("Invalid teleport [%s]: %s"):format(teleportResult.Name, errorMessage))
end
SafeTeleport(targetPlaceId, {player}, teleportOptions)
end
TeleportService.TeleportInitFailed:Connect(handleFailedTeleport)
return SafeTeleport