I’ve always coded my round based games just by using lots of integrity and validity checks to account for players leaving/characters not being loaded, etc. Obviously I could just use a pcall and clear the round + go to an intermission if the status code returns false, but I’ve been weary of this because of the cost of pcalls and having the entire code for each round in a pcall seems like a lot of work on the server.
What’s a better way to protect the natural loop of round-based games from breaking?
Wrap the loop in a pcall
Constant validity checks
0voters
Would love some insight for future round-based games that I make, so feel free to elaborate on your choice in the replies.
P.S: I couldn’t decide if this should go in Development Discussion instead of Scripting Support because it is more of a discussion, but I’m not sure if I’m being clueless and there’s only one right answer that I’m not aware of which is why I’ve started this thread in Scripting Support.
Edit: As I suspected, this really isn’t a debate and I was unfamiliar with the specific use case for pcalls. I’ve marked an informative reply as the solution and closed the poll. Thanks for the help!
So the thing about pcalls is that they should really be avoided. They aren’t efficient, they can excuse bad coding, and they do have limitations. pcalls should only be used in situations where it is unavoidable. You can fix your own code and you should, but some functions (Such as HttpService, DataStores, etc) have a chance to fail since they rely on web services. You can’t control when they fail, and you can’t fix it. That is when you would use a pcall, but only if the service failing causes your script to error and fail.
If you are worried that your game might have game-breaking bugs in it, you can probably use LogService to determine if the game control script has had an error, then have it send you a message with HttpService or something so that you have the output and similar diagnostics, and then warn players that the server is broken and to join a new server whilst you fix it.
pcall is meant for handling exceptions that are out of your control, i.e. web requests. You can’t guarantee a web request will be successful, so it would be a good idea to wrap the web request in pcall so that you can handle failures without terminating the entire script.
If the issue of
is in your control you should avoid pcall. I think you should just discard these players, seems to be easier.