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)
end
end)
module script:
local module = {}
function module.getMouse(char, camera, X, Y)
local rayParams = RaycastParams.new()
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
end
return module