I get how pcall works, but I don’t get when I should use it.
Use PCalls to handle things that could possibly error, such as datastores or Http requests, or if you're finding code doesn't work, you could do something like:
1 | local success, err = ypcall( function () |
2 | ppppppppppprint( "i error!" ) |
3 | end ) |
4 | if not success then |
5 | print ( "Oops! I errored: " .. err) |
6 | else |
7 | print ( "I succeeded!" ) |
8 | end |
This is a good tool for code errors, it is a good ally of a function if you want to keep track of what went wrong, you can use pcalls to keep track of your code carefully, putting one at each important step.