Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Is it possible to retrieve the player's mouse in a regular script?

Is it possible to get the player's mouse in a regular script as opposed to a localscript?

2 answers

✓ Accepted answer

It is possible, though this method may become unusable one day. You must use RemoteFunctions. For the server script (whatever name), have the following:

local mouseGet = Game:GetService("ReplicatedStorage"):FindFirstChild("MouseGet") or Instance.new("RemoteFunction", Game:GetService("ReplicatedStorage"))
mouseGet.Name = "MouseGet"
game.Players.PlayerAdded:connect(function(Player)
    local playerMouse
    Player:WaitForChild("PlayerGui"):WaitForChild("MouseGetControl") --Wait for the control script to load.
    repeat playerMouse = mouseGet:InvokeClient(Player) until playerMouse --Get the player's mouse.
    --Do whatever you want.
end)

Now, have a script in the StarterGui called "MouseGetControl":

local mouseGet = Game:GetService("ReplicatedStorage"):FindFirstChild("MouseGet") or Instance.new("RemoteFunction", Game:GetService("ReplicatedStorage"))
mouseGet.Name = "MouseGet"
mouseGet.OnClientInvoke = function()
    return Game.Players.LocalPlayer:GetMouse() --Return the mouse object.
end

This is untested, however I am confident that it will function correctly.

No, servers don't have a mouse. And it's not advised to send mouse info to server, because that is slow and pointless process.

Edit: But seriously, why would you want a blind machine to know mouse data?

You want to know when everyone is hoovering over one block? Okay, make a client script and use remote event, to notify server when player is looking at something and when not.

It is possible to send raw mouse data to server, just like mentioned above, but it's very inefficient and highly discouraged.

This discussion is preserved as it was. New answers, comments, and votes are closed.