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

Why can't I get the player's mouse?

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

local player = nil

if script.Parent.Parent:IsA("Model") then
	player = game:GetService("Players"):FindFirstChild(script.Parent.Parent.Name)
else
	player = script.Parent.Parent.Parent
end

print(player)

local mouse = player:GetMouse()

print(mouse)

prints (the player's name) and after it prints nil

3 comments

0

uhh use remoteevents u cant get mouse on server only local scripts only the mouse.position and what not can actually be transferred to the script not the actual mouse

0

I need to do a mouse button pressed event

0

":GetMouse()" only returns the mouse being used by the client. Is this your goal?

1 answer

✓ Accepted answer

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]

local rs = game:GetService("ReplicatedStorage")
local getmouse = Instance.new("RemoteEvent", rs)
getmouse.Name = "GetMouse"

getmouse.OnServerEvent:Connect(plr, mouse)
	if mouse == "MouseButton1Down" then
		print(plr .. " just clicked MouseButton1Down!")
	end
end)

[In a Local-Script]

local event = game:GetService("ReplicatedStorage"):WaitForChild("GetMouse")
local mouse = game.Players.LocalPlayer:GetMouse()

mouse.Button1Down:Connect(function()
	event:FireServer(game.Players.LocalPlayer.Name, Button1Down)
end)

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