Pcalls / Error Catching

Okay, this is more of a general question I have for a very experienced and knowledgeable developer who may have information on this question.

Maybe this is just my brain overthinking however, my question is, how often and when should I use Pcall, and how do you prevent function from erroring?

For example, this is something I was thinking about. Lets say I have a function that moves a player from point A to Point B, but when the function runs and goes to move the character, the character has died before it could register the function. it would error and say there is no character.

Maybe I am overthinking? what are some tips to avoid these errors?

you use pcalls for asyncs and roblox services that can fail like datastores. you shouldn’t use it as a permanent fix to your code and would be a lot more efficient if you debugged it: in your case checking if the character exists before doing anything with it otherwise stop running the code

1 Like