So I use pcall in my scripts for datastore requests but really don't know where else I should use them. I would appreciate it if someone could give me some pointers so that I have a safely scripted game. I am not asking anyone to script for me, I just want to know what I can use pcall most effectively for.
Where can I use pcall most effectively?
1 answer
pcall should be used rarely, when making unreliable Roblox API calls that could error, including HttpService and DataStoreService. It can also be used when dealing with certain input, such as executing arbitrary user-inputted Lua, or when working with remotes server-side, to catch errors (though event listeners each get their own thread, so your game won't break, output clog could be annoying).
I am against Roblox's API design in regards to pcall. It shouldn't be used as a try-catch mechanism in Lua, and they should instead return error booleans and error enums.
If you ever find you want to use pcall in another situation, you should instead returning success booleans / error codes.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Thank you.