Problem with GetMouse() function Help

Hi, my problem is this:
I want to do a simple server-side script to simulate an attack with a tool, but when I try to get the player’s mouse, my script doesn’t detect the mouse…

-- SERVER SCRIPT || PARENT OF THE SCRIPT = TOOL

tool.Equipped:Connect(function()
	local char = tool.Parent
	local plr = players:GetPlayerFromCharacter(char) --Getting the player who owns the tool
	
	if char then -- If the player character exists (works fine...)
		local mouse = plr:GetMouse()

		print(mouse) -- (Actually this prints nil)

        mouse.Button1Down:Connect(function()
        -- [REST OF SCRIPT...]
        end)
    end
end)

I have a doubt if the problem comes because it is a server script
Or if I have to change it to a client script.

1 Like

plr:GetMouse() is only used in a client sided script. Change it to client side.

2 Likes

Simply use Tool.Activated:Connect(function()
That connects if the player activates the tool. (clicks while holding tool)

Make that function then inside of it add all the logic that needs to take place when the tool is activated. :slight_smile:

1 Like

I had it in mind, until I wanted to add a reload time to the tool, so I discarded the activated option, thanks anywayy

2 Likes

why dont u use a local script with a remote event?

1 Like