Most efficient way of continuously tracking mouse movement on server

I’m trying to make a part that continuously looks towards where the player is pointing their mouse and I want it to be server-side. The only way I understand to accomplish this is by firing multiple RemoteEvents each second but it seems like a very inefficient solution to what doesn’t appear to be the most complicated problem.

If it is the only solution, how many RemoteEvents can one reasonably fire every second (assuming the one parameter is a just an integer) without it affecting the performance too much?

1 Like

If you script running only on server (it’s not fired by RemoteEvent or RemoteFunction), you can fire one RemoteFunction to get mouse data per your script tick. Also you I want to say that you can use player:GetMouse() only on client-side.

1 Like

What exactly are you trying to achieve with this tracking?

1 Like

read the post :sob: they want a part that looks at the player’s mouse on the server

and also no, firing remote events especially unreliable ones a lot isn’t inefficient

1 Like

There was another topic discussing solutions for a problem like this

The solution was using :SetNetworkOwner and changing the part on the client side.

I read this blog post a while back and ended up using UnreliableRemoteEvents for positioning a cannon towards a player’s mouse position in world space. Pairing Linear Interpolation w/ UnreliableRemoteEvents for things like this is HIGHLY slept on.

3 Likes

This is what I was hoping to do to begin with. I discovered you can’t set network ownership of anchored parts however so it wouldn’t work unfortunately.

This is your solution. Don’t worry about performance until you actually see an objective hit to performance.

1 Like

That’s good to know! Thank you to all the folks mentioning UnreliableRemoteEvents.

If you do end up running into performance issues, you can move the CFrame updates to the Clients and have them handle the interpolation and what not. I did this but, it’s very important that you only send the rotational data calculated on the client to the server so they can’t mess w/ positioning. From there, validate and broadcast said changes to the other clients via an UnreliableRemoteEvent.

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