Why does my ray only detect a player from behind?

I added a dummy into my game to see if this raycast would return it whenever I click and it does but only for one side. I can’t hit it from the opposite side for some reason. Does anyone know what the problem is? If so I’d like some advice on how to fix this issue please!

local remote = game.ReplicatedStorage:WaitForChild("detection")
local player = game.Players.LocalPlayer

remote.OnClientInvoke = function(r)
	if player.Character then
		local plrchar = player.Character
		local humroot = plrchar:FindFirstChild("HumanoidRootPart")
		local startPosition = humroot.Position + humroot.CFrame.lookVector
		local endPosition = humroot.Position + humroot.CFrame.lookVector * r
		local ray = Ray.new(startPosition, endPosition)
		local p = workspace:FindPartOnRayWithIgnoreList(ray,plrchar:GetChildren())
		local foundPart
		
		if p and p.Parent:FindFirstChild("Humanoid") then
			print(p.Parent)
			return p.Parent, "No"
		end

	end
end

I tested your script and seemed functional to me can you clarify the problem you’re having?

What is r? Is this the distance you want to cast your ray?

Ray.new’s 2nd parameter is Direction (could also be called Length), not Position. You need to use a directional vector (think object space from the startPosition).

Example:

local distance = 50

local startPosition = rootPart.CFrame.p
local direction = rootPart.CFrame.lookVector * distance

local ray = Ray.new(startPosition, direction)

This would cast a ray from the center of the rootPart, 50 studs in the direction the rootPart is facing.