Ray not finding character parts if there's something behind it

So I’m casting a Ray to detect clicks on character body parts, as the mouse automatically filters those:

local clickedPart = workspace:FindPartOnRay( Ray.new( camera.CFrame.Position, mouse.Hit.Position ) )

But something strange happens: when I click on parts of my character, while looking at it from such an angle that the only thing behind the character is the skybox, and then I print the “clickedPart”, it prints the names of the parts correctly; however, if I look at my character from such an angle that the baseplate is behind it, I always get “nil” printed.

This doesn’t make much sense to me, as not even Baseplate gets printed.
Does anyone have an idea?

This is what I mean by skybox behind character and baseplate behind character:

unknown unknown1

If you’re trying to determine if the player has their mouse on a body part on their character, you could try the following code:

local RANGE = 20

local mouse = game.Players.LocalPlayer:GetMouse()
local ray = Ray.new(mouse.UnitRay.Origin, mouse.UnitRay.Direction*RANGE)
local hit = workspace:FindPartOnRay(ray)

if hit then
print(hit.Name)
end

Wha, that works, thank you!

Any idea why my Ray didn’t always detect the parts?

Here’s what I want you to do make a part in front of the character and then try if it works that means there’s some other issue, but if it still doesn’t then it has something to do with the camera, we can work our way up from there.

I just noticed this now, you set it up like this:

Ray.new(camera.Position, mouse.Hit.p)

The first argument is the origin, or starting point, of the ray. The next argument is the ray’s direction.

However, the Hit property of the mouse isn’t a direction, it’s just the position of the mouse in the game world.

So I’m sure you could see how this yielded inaccurate results.