Error in my custom mouse script

Hi a while back I made a custom mouse script because player mouse is deprecated and user input service doesn’t support it. while using the code in a script I decided to turn it into a module script to make using it easier since I would probably use it often but for some reason it doesn’t work. Here’s the error message:

20:24:59.321 Argument 2 missing or nil - Client - Mouse:7

local script:

local player = game:GetService("Players").LocalPlayer
local Uis = game:GetService("UserInputService")
local replicatedStorage = game:GetService("ReplicatedStorage")

local requestGrab = replicatedStorage.RequestGrab
local camera = workspace.CurrentCamera
local char = player.Character or player.CharacterAdded:Wait()
local module = require(replicatedStorage.Mouse)

Uis.InputBegan:Connect(function(input, processed)
	if processed then return end
	if input.KeyCode == Enum.KeyCode.E then
		local X, Y = Uis:GetMouseLocation()
		local mouse = module.getMouse(char, camera, X, Y)		

module script:

local module = {}
function module.getMouse(char, camera, X, Y)
	local rayParams =
	rayParams.FilterDescendantsInstances = {char}
	rayParams.FilterType = Enum.RaycastFilterType.Blacklist
	local unitRay = camera:ViewportPointToRay(X, Y, 0)	
	local ray = workspace:Raycast(unitRay.Origin, unitRay.Direction * 1000, rayParams)
	return ray
return module
local X, Y = Uis:GetMouseLocation()

Replace this line with: local X, Y = Uis:GetMouseLocation().X, Uis:GetMouseLocation().Y
I think it returns nil or missing because you have essentially assigned only one Variable (either X or Y) to Uis:GetMouseLocation. The other variable returns nil.

Thanks it’s working now :slight_smile: