How do I prevent hitting through walls?

I have a melee system. It uses magnitude, but however, I want the player to have a clear, non-obstructed view of them so they don’t get hit through walls. For this, I have used raycasting.

The ray projects in the direction of the nearest character (who was picked up by magnitude), and sees if what it hits has a humanoid.

Unfortunately, from users, I’ve gotten complaints about the melee hitboxes, and I have experienced their troubles.
Sometimes a hit will not register even when there is a clear view of the player, I believe that the raycast is rather hitting something else. However it’s needed to make sure that the player is not hitting people behind walls.

Is there a better way to do this?

EDIT: Edited the title so it’s more clear, as I’m not getting any responses.

Maybe you could use RaycastParams.FilterDescendantsInstances if you haven’t already to filter out parts from the weapons or the character who is attacking with the weapon, because those can still be detected from the raycast.

Where you start the raycast also matters, because if a weapon can clip through the wall and you send a raycast from there, it has a chance of not detecting the wall at all.

Sorry for the belated response.

I do use FilterDescendantsInstances and I start the raycast from the character’s HumanoidRootPart, its gotten me negative responses from the community…

Thank you for giving me a response though. :+1: