Should I use InvokeClient()?

Hello!
So, InvokeClient() seems to be considered bad practice and that’s why I’m making this post.

In my game a player can activate an attack which fires a remoteEvent that then requires a module for that attack. In that module I would later want to know the players current mousePosition (Like 1 second after requiring the module).

This seems like a perfect use case for InvokeClient in my opinion, but that’s why I wanted to ask if there are any other more common practices to achieve Server → Client → Server communication in this matter.

I am also exploring the possibility of having a remoteEvent that fires to the client where another remoteEvent then fires back to the server and then receiving it.

Any input would be helpful.

I think your looking for Remote Functions

Yes, that is precisely what I’m asking about.

Use them to send information from the server to the client and back to the server and vice versa. That’s what they are used for. It’s a lot more practical than 2 remote events.

Basically,
Use remote Events for communication between server and client(One way)

Use remote functions to return back information after firing it(Two way)

1 Like

Consult the documentation.

Notably you would need to worry about the client throwing an error on the server, and possibly hanging forever. This means you would need to worry about wrapping it in a pcall and/or new thread or having a maximum response time. In practice it seems much easier and safer to just fire a remote to the client and have the client fire one back.

2 Likes

You should Never use Invoke client due to the fact its a bad practice to give the client authority over a request, since an exploiter could very easily yield that client invoke request, which would also yield the server-side thread forever.

If the server needs the clients mouse position, the client should be using a remote event to replicate that data to the server, but the server should not be yielding for this data to complete what it needs to do.

There are a few edge cases where a server might want to wait for a client to complete what it’s doing before continuing, therefore giving the client authority over that request (like waiting for a client to completely load the game and its assets before spawning the player in), but that’s not the case here.

I hope this helped at all.

4 Likes

You can just send the request using a separate thread and wait a maximum value for the request result to exist. If it doesn’t exist, close that thread and move on. This is simply how networking in real servers work.

1 Like

No. I have never found a valid use for InvokeClient. Based on your post it sounds like you’re programming some type of ability. Player inputs for abilities should be handled on the client to prevent delay. Unresponsive gameplay never feels good. Sanitize the inputs and data the client sends to the server, but handle the player’s inputs on their client.

In the “real servers” / the industry it’s not common to query the client for information like this.