Hey devs,
I’ve been making a system that re-teleports the players to the same place after the round is finished, but everytime it teleports me, it gives me this error :
I am not sure if this is my fault trying to do something that’s not possible (re-teleporting players to the same place) or Roblox having issues since, as you can see in the image, I am LITERALLY in the server when it gives me the error… Should I try making another system, teleport players to another place, or just wait because it might be a roblox bug ?
Script 1 :
local timeLeft = game.ReplicatedStorage.TimeLeft
local RoundRunning = false
local TeleportationModule = require(game.ServerScriptService.TpModule)
if RoundRunning == false then
wait(5)
RoundRunning = true
print("round running")
local secondPassed = 20
while wait(1) do
if secondPassed > 0 then
secondPassed = secondPassed - 1
timeLeft.Value = secondPassed
elseif secondPassed == 0 then
TeleportationModule.teleportWithRetry(7751149102, game.Players:GetPlayers())
timeLeft.Value = 0
print("The round's done")
RoundRunning = false
break
end
end
end
Script 2 (from the devhub):
local TeleportService = game:GetService("TeleportService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TeleportModule = {}
local RETRY_DELAY = 2
local MAX_WAIT = 10
-- Create remote event instance
local teleportEvent = Instance.new("RemoteEvent")
teleportEvent.Name = "TeleportEvent"
teleportEvent.Parent = ReplicatedStorage
function TeleportModule.teleportWithRetry(targetPlaceID, playersTable, teleportOptions)
local currentWait = 0
-- Show custom teleport screen to valid players if client event is connected
teleportEvent:FireAllClients(playersTable, true)
local function doTeleport(players, options)
if currentWait < MAX_WAIT then
local success, errorMessage = pcall(function()
return TeleportService:TeleportAsync(targetPlaceID, players, options)
end)
if not success then
warn(errorMessage)
-- Retry teleport after defined delay
wait(RETRY_DELAY)
currentWait = currentWait + RETRY_DELAY
doTeleport(players, teleportOptions)
end
else
-- On failure, hide custom teleport screen for remaining valid players
teleportEvent:FireAllClients(players, false)
return true
end
end
TeleportService.TeleportInitFailed:Connect(function(player, teleportResult, errorMessage)
if teleportResult ~= Enum.TeleportResult.Success then
warn(errorMessage)
-- Retry teleport after defined delay
wait(RETRY_DELAY)
currentWait = currentWait + RETRY_DELAY
doTeleport({player}, teleportOptions)
end
end)
-- Fire initial teleport
doTeleport(playersTable, teleportOptions)
end
return TeleportModule
Thanks in advance !