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

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

Asked by 10 years ago

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

2 answers

Log in to vote
3
Answered by 10 years ago

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.

Ad
Log in to vote
-1
Answered by 10 years ago

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.

Answer this question