Do i need Pcall for TeleportService?

Im using TeleportInit to detect Teleport fails, but i saw some Scripts and they are using Pcall() with TeleportService. In the Official Roblox Website i dont see any Pcall() in the Teleport Scripts. Do i need to use Pcall() or not?

It is indeed a good way to use pcall() as it handles errors (which are sometimes common for TeleportService) and doesn’t break potential game mechanics.

1 Like

But im using TeleportInit already, do you know if Pcall is really needed for TeleportService?

Better safe than sorry, from my perspective.

1 Like

pcall is necessary for API that has little to no control for your system. API calls are bound to have pcall(or protected call in full name), just to avoid errors causing complete system failure and handling errors.

That said, you should use pcall to handle what would the system do if TeleportService somehow fails.

1 Like

Do i also need pcall to reserve a server? Or just to teleport?

The latter is more preferable, but I think both is needed since I read the documentation that it yields, which means the generation happens somewhere outside the game instance.

Thanks, do you also know why in the Documentation all the Scripts are without pcall()?

They’d typically work as per usual and only demonstrate the functionality. Not error handling though.

Okay and can i check pcall instantly? So after i do pcall() -- Reserve Server Code end can i check instantly if pcall() successed and then continue?

It actually returns something. To check:

local success, response = pcall() -- response depends on if the function within returns something, sometimes it's the error message

if success then -- not success if you expect to do something in error
    -- whatever thing you do if it works

Thanks and if Pcall fails, do it fail for one Player or for all the Players in the Table?

It fails on the thread, to be precise. If it was on a LocalScript, it will fail for one. If it was on server, it will fail for all.