I am working on a game which has some extremely intricate mechanics, which occasionally throw errors because of things that are 1 in 10,000 of actually happening – yet are basically unavoidable because of Roblox limitations. I’ve done everything I can to mitigate these errors, however, they’re still occasionally thrown.
I rarely utilize pcalls in my scripts, and I feel like having a contingency plan in case some of my functions fail would be a big help.
That being said, I am unsure of whether or not pcalls can be overutilized – thus leading to performance drops or larger delays in client/server communication.
I read some posts on the developer forum about pcalls, however, none of them really elaborate on when NOT to use pcalls.
You can’t get the error message in console with using pcall(you can but you have to print which takes more code space) so pcall is really good for checking roblox side of error likes internal server error that your code don’t get or something example likes you tryna get the player avatar but it doesn’t load on first try so you wrap it in pcall to not get an error and able to retry that without the code stopping. I use pcall for loading npc avatar based off avatar on roblox and there a lot of errors if you have a lot of API call.
If you’re uncertain that you can’t fix something or it will never be fix you should use pcall. Don’t use pcall if you can definitely fix the problem.
Edit: If you’re scare of an error, get people to test for a month minimum or release a demo and then close it until you fix all the problems.
Just wrap em in pcalls, they don’t use much resources anyway. You can just check an error by printing the errormessage:
local success, errormessage = pcall(function()
end)
if errormessage then
warn(errormessage)
end
Obviously I don’t recommend wrapping everything in pcalls to begin with because if you’re starting to make the game you won’t notice the errors, or it’d be tricky to find them. Only wrap em once you’re done with the game and you know things are having errors.