Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Is there any way to access a player's mouse through a server script?

Asked by 6 years ago
Edited 6 years ago

Any way to do this? I need this since it is involved in a gun. I'm new to filtering enabled and I don't know how to transfer the mouse from a local script properly as it would only make a mouse variable for the OnServerEvent function but, not the whole script.

I resorted to putting the main script into a server script. The only thing left that stops it from working is finding a way to get the mouse.

1 answer

Log in to vote
0
Answered by
Mayk728 855 Moderation Voter
6 years ago
Edited 6 years ago

You can get the mouse's position using RemoteFunctions.

Server; Asking the client for the mouse position

local RemoteFunction = game.ReplicatedStorage:WaitForChild('RemoteFunction')

local MousePos = RemoteFunction:InvokeClient(game.Players.Player1,"MousePosition")

print(MousePos)

Client; Giving the server the mouse's position.

local RemoteFunction = game.ReplicatedStorage:WaitForChild('RemoteFunction')
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

--This acts like a normal function, so it can "give" anything the server asks in return.
function RemoteFunction.OnClientInvoke(Argument)
    if Argument == "MousePosition" then
        return mouse.Hit.p
    end
end

The above script is just an example. If you're using a Tool to get the mouse's position, you can just put a ServerScript, LocalScript, and RemoteFunction inside the tool to make it easier.

Ad

Answer this question