Mouse Target Filter Issue

Hello, DevForums! As the title suggests, I wanted to use the mouse target filter with invisicam for my game. I researched a bit and found a solution to my question, using this code:

local Players = game:GetService("Players")
local player = Players.LocalPlayer 
local mouse = player:GetMouse()
mouse.TargetFilter = game.Workspace.MouseIgnore

While it works fine, the issue is that even when I am in front of a wall and not behind it, when I click on it, it still aims for what is behind it.

To sum it up: I wanted to find a way to make the mouse target ignore a part, but only when the player is behind a wall.

I’m not sure what the end goal is. But it may be better to use raycasting for this. You can use the mouse to get the initial direction vector and then use a raycast to determine part hits/ignores.