We are generally advised to stay away from RemoteFunction:InvokeClient() because an exploiter could return bogus data or yield indefinitely but are there any circumstances where this would be OK? Are there any acceptable use cases?
For example, what if I set up the system such that the client will not be invoked again until they responded to previous invocations? So if an exploiter yields indefinitely they cannot create an indefinite number of yielding server threads?
Yes, I think there are a few uses where it could yield infinitely and not have much of an impact for anyone but themselves, and assuming you aren’t relying on the client for any important game logic, and you’re properly handling cases where an invalid response is given.
For example, player buys a crate and they get an item that they already own. Invoke the client and they can either keep the dupe or exchange it for coins, then return whether they keep or exchange to the server.
Another one is if you need to get the player’s device, you can return if touch is enabled, keyboard is enabled, and mouse is enabled.
Can’t really think of another one off of the top of my head though, but I think cases where you give basic decisions to the player and said decisions don’t affect other players, it’s probably fine.
There are no cases where it is better to use InvokeClient, even if there are cases where it’s not better or worse and you handle it properly (running it on it’s own thread) I would still opt for RemoteEvents for consistency.
The general model is Client → Server,
As in the client should always be asking the server and the server responds. (the server can also send information and the client reacts on it)
Example:
Client says to server “Can I buy a random crate?”
Server checks their money, lets them buy a random crate, and they unlock a random item; the server sends the item back to the client
Client says "I already have this item, can I have cash instead?