When I do player:GetMouse()
on a server, it returns nil, How can I get the mouse?
Heres the code I wrote on a tool
01 | local player = nil |
02 |
03 | if script.Parent.Parent:IsA( "Model" ) then |
04 | player = game:GetService( "Players" ):FindFirstChild(script.Parent.Parent.Name) |
05 | else |
06 | player = script.Parent.Parent.Parent |
07 | end |
08 |
09 | print (player) |
10 |
11 | local mouse = player:GetMouse() |
12 |
13 | print (mouse) |
prints (the player's name)
and after it prints nil
You are able to get a player's mouse by using the :GetMouse() feature. Keep in mind that ":GetMouse()" will only return the mouse being used by the client. Just because of that, we are going to make an EXAMPLE of a GetMouse function Remember that this is just an example of what you can do with GetMouse
For Example: [In a server-sided script]
1 | local rs = game:GetService( "ReplicatedStorage" ) |
2 | local getmouse = Instance.new( "RemoteEvent" , rs) |
3 | getmouse.Name = "GetMouse" |
4 |
5 | getmouse.OnServerEvent:Connect(plr, mouse) |
6 | if mouse = = "MouseButton1Down" then |
7 | print (plr .. " just clicked MouseButton1Down!" ) |
8 | end |
9 | end ) |
[In a Local-Script]
1 | local event = game:GetService( "ReplicatedStorage" ):WaitForChild( "GetMouse" ) |
2 | local mouse = game.Players.LocalPlayer:GetMouse() |
3 |
4 | mouse.Button 1 Down:Connect( function () |
5 | event:FireServer(game.Players.LocalPlayer.Name, Button 1 Down) |
6 | end ) |