So I have a bomb that destroys things, but what it really does is stores the parts and makes a clone unanchored prop and after a minute it restores the item that was destroyed back to the original parent. The issue is that lets say half a scripted door is broken then some of the parts are no longer in the model that the script is suppose to detect. If I put it all in a pcall then when the parts are “destroyed” the pcall will call an error and the script wont error and stop and will allow the script to check every time the handle of the door is clicked. I see this as a solution to my problem, but I’ve heard from places that pcalls should be limited if possible and so I wonder what are the disadvantages of using a pcall in the way I plan on using them?
Pcall should never be used to prevent an error that you have the control to fix. Pcalls suppress line numbers and stack traces in your errors and make debugging harder. Having a bunch of pcalls everywhere is not efficient or easy to read. They’re not so inefficient that I would say don’t use them for the inefficiency, it’s just really not a good practice. I think I speak for all of us when I say that we here at ROBLOX strive to be better than EA Games. Let’s fix our stuff properly instead of using ugly workarounds.
Pcall however should be used when you don’t have control over the error. For example with data stores or HTTP service, you can’t control when the functions have an internal error because the code behind HttpGet and SetAsync is not your code and you can’t fix networking issues. This is a good time to use pcall.