This is like the fourth time in the past few days I’ve had something erroring inside of a pcall, and roblox throws a full error and stops run-time instead of continuing with the game.
Is this a studio-only thing? Is something wrong with pcall? Wtf?
This is like the fourth time in the past few days I’ve had something erroring inside of a pcall, and roblox throws a full error and stops run-time instead of continuing with the game.
Is this a studio-only thing? Is something wrong with pcall? Wtf?
Is players a table? And are there even players in the table?
like @yoshicoolTV pointed out, players has to be an array of players:
local players = {plr1,plr2,plr3} --and so on
I know players is an empty table. I know it errored. I don’t care about that, that’s a 1 second fix.
The problem is, now I can’t trust pcall, because it’s just letting the code throw errors. The whole point of the pcall is to let the code keep running after an error happens. How do I know TeleportService isn’t going to throw a TeleportService.Flooded error? Those randomly happen and is the whole reason the pcall is there, but now I have no way to know if that would just break the entire game instead of doing what pcall is supposed to do.
I see your issue now. I myself only got it once during testing a few minutes ago. Could you mayve check if code executes after the pcall (EDIT: I realised that pcall and ypcall merged into todays pcall - my bad)
The important question here is if it stopped execution or not. E.g., if you had a print statement on line 15 outside of the pcall, does that print statement still work? If so, pcall is working as expected, regardless of an error being outputted.
If I resume in studio, yes. So I guess it’s not broken.
This is a new studio behavior though, right? I don’t think pcall errored mid-studio testing previously.
There is nothing wrong with pcall
, your code is just incorrect.
??? Pcall literally returns the reason the code errors as a variable, and I warn() that so that I can know what happened without stopping all of studio.
Why does it completely pause studio’s running now - if I wanted it to stop studio I would either not have the pcall or error() the pcall result.
Nevermind, the SafeTeleport Module has these lines:
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
So it isn’t the pcalls fault it’s just a feature of the module
That would be great if that was the error it gave me, but that’s a completely different string, and not included in the traceback either.
Do you use the SafeTeleport Code from Roblox?
(that one btw)
Yes, that’s the code I’m using.
I want you to look at the code and find something called “error(”
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
I haven’t changed the string, and the line it’s erroring at is the line with the pcall, not the line with the error.
This code will make your code error, since you didn’t provide anything right it will error due to the else and format just edits the string a bit
Format edits the string, but it should fill in the blanks, it shouldn’t be changing the string entirely to a completely different message. Additionally, that line should be included in the traceback, not the line of the pcall.
Then how about you remove that line and see if it errors again
Ran it again with that line commented out. Got the same error at the same line.