Getting the mouse position with a module script

So I have a local script which finds when the player chats and if it’s a certain word like “carrots” it fires a remote, the remote passes the players mouse.hit.position to a server script. The server script uses a module script to load in a part that I want to tween to the mouse position. Can I get the mouse position from the module because it will make it 10x simpler.

(not sure if i explained that well)

If the module script is required by a localscript (meaning the localscript calls the require() command on that module) then yes. The module is able to get the mouse the same way a localscript would. However, if a ServerScript is calling the require() function on the module then it will not be able to get the mouse position, unless the client sends it to the player somehow

2 Likes

If you’re trying to use :GetMouse() or any similar functions to get the player’s mouse, that can only be done on the client side in local scripts. If you want to access any information about the player’s UI (including the mouse) on the server, you’ll have to pass that information through a RemoteEvent or a RemoteFunction.

For your use case (if I read this correctly), it may be easiest to create a RemoteFunction that the server can use to request the data you need from the client. This is to say that you’ve require()'d the ModuleScript on the server.

If you require()'d the ModuleScript on the client, then it runs on the client as a local script would, and you can access the mouse like any local script would be able to.

3 Likes

mmmh alright, well I guess i’ll just tween it on the server script thanks for the help anyways.