Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Where can I use pcall most effectively?

Asked by 6 years ago
Edited 6 years ago

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.

1 answer

Log in to vote
0
Answered by
Avigant 2374 Moderation Voter Community Moderator
6 years ago

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.

0
Thank you. User#21908 42 — 6y
Ad

Answer this question