Optimized Mouse Aiming Help

I currently have a system for getting the player’s mouse position from the server, but recently I’ve noticed that it’s very inefficient and is a likely culprit of Server lag.

In-Game, the Script Profiler notes that the OnServerEvent takes up almost 22% of the time!

The current system fires a Remote roughly every 0.2s to update the Server on where the player’s mouse is currently positioned. It updates so often for precision, as this is practically required in my game.

Mouse aiming in my game is used for Projectiles, as well as aiming other attacks (some of which require constant updates on the Mouse’s position as they have long Wind-ups or constant attacks at the player’s cursor)

I can’t see sending mouse Data along with the “Use Move” action working, as a player may want to redirect their aim during the windup of a particular move.

Are there any other reliable and performant alternatives for updating the Server with a player’s mouse data? I’m trying to optimize my game, as performance has been a growing concern within my player base.

Inside your tool, you can just have a local script and a server script, then evertime the tool is activated just fire a remote event from the client with the mouse position as a parameter.

The best alternative is to stop doing what you are doing right now because that is a horrible practice.
You should not update the mouse position on the server, that is completely irrelevant to the server.
Mouse Input is irrelevant to the server at all times until you do world interaction (like firing a bullet,) your system is wrong because you update the mouse position even when it is irrelevant to the server…
You should consider only sending the mouse position over when the action is actually being sent (like firing projectile sends along the mouse position)

I do not know why you are updating the mouse position so frequently, but if it is to “prevent” cheating then that does not stop anything, and if it is for anything else then you should not be doing that regardless.

I have noted in my post that this practice is horrible, and I am attempting to look for a solution that provides a more performant alternative.

I have also stated that sending mouse information when firing a projectile probably wouldn’t work in my game, as some of the moves require constant mouse position updates (because there is either a rapid fire of projectiles or a slow windup)

I appreciate the response but I do think that you aren’t understanding my issue at all.

This isn’t for “preventing cheating”, the mouse update is because the server quite literally requires the mouse information to aim a projectile in the right direction. The projectiles are server sided, hence requiring the mouse information from the client.

I am trying to find a more optimized method of receiving mouse information from a client.

Sorry, I missed the part where you needed to update the projectile position throughout the “shooting process”, and allow me to re-word my response.

That still does not mean you have to send the mouse position as frequently as you are sending it, you would only need to send it for the span of time the server actually requires it.

Right now, you are just always sending it regardless of whether or not the client is actually doing something (from what I understood,) so instead of that, just send it only when needed.

(Projectile fired → keep sending mouse information for the amount of time the “action” is up for)
As for “projectiles are server-sided”, that is also… technically a bad practice, your projectiles should be visually rendered on the client and validated on the server for the best server and user experience.

I am well aware that this is bad practice, and that is why I made this thread.

I also am aware that I need to stop using the current method (as it has proven itself to be laggy).

I’ll try out your solution for only sending the information when it is required, do you think the following steps below would work?

  • Move Begins
  • Move toggles a Value to True, signaling that the mouse position should start updating
  • Client sends mouse information as long as this value is set to true
  • When Move no longer needs the Mouse Position, it sets the Value to False
  • When this Value is False, it signals that the client no longer needs to update the server with mouse information

I mean if you really want to keep it mostly server-sided, then I guess so, that is an approach you can try to lower the network usage.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.