How to get mouse position in 3d ignoring UIS

Im trying to get the mouse position in 3d, but when i click a UI button or a CAS mobile button the mouse position in 3d is updated. Is there a way to not update the mouse position when i click a button

If you are using the UserInputService there is a boolean input that is the second parameter to InputBegan, InputEnded, etc… You can check if it is true, if it is true you can just return as that means it is a UI button.

example:

userinputservice.InputBegan(function(input, processed)
if processed then return end – this will ignore cases when a user is focused on textboxes or clicking buttons
end)