workspace:Raycast() returning nil even while pointed at a part

I am trying to raycast from the player to detect what part they are looking at. The issue is it keeps returning nil even if I am looking at a part. However, when I am right up close to a part it does return the raycast result as expected.

local player = script:FindFirstAncestorWhichIsA("Player")
	local lookDir = game.ReplicatedStorage.remoteEvents.getCameraViewVector:InvokeClient(player)
	local ray = workspace:Raycast(player.Character.Head.Position,
		lookDir,
		RaycastParams.new(
			{
				player.Character.Head,
				player.Character.Torso,
				player.Character.HumanoidRootPart,
			},
			Enum.RaycastFilterType.Blacklist,
			false,
			0
		)
	)
	print(ray)
	if ray.Instance ~= nil then
		if ray.Instance.Parent:GetAttribute("isVendingMachine") then
			print("you have bought a",ray.Instance.Parent:GetAttribute("gives"))
		end
	end

here’s the script that gets the view direction in case that’s the issue:

local remoteFunction = game.ReplicatedStorage.remoteEvents.getCameraViewVector

remoteFunction.OnClientInvoke = function()
	local vector = game.Workspace.CurrentCamera.CFrame.LookVector
	return vector
end

You should increase the value, since LookVector is an unit vector with the direction of where the camera CFrame is looking. You can do this by multypling it to a high number.

local ray = workspace:Raycast(player.Character.Head.Position,
		lookDir*200,
		RaycastParams.new(
			{
				player.Character.Head,
				player.Character.Torso,
				player.Character.HumanoidRootPart,
			},
			Enum.RaycastFilterType.Blacklist,
			false,
			0
		)
	)

Also, a ray is very thin, so if there’s a small part you will have to look at the part exactly direct so the ray can detect it. In this case you should instead use Camera:WorldToScreenPoint().

Thanks! I didn’t realize that the size of the Vector3 affected the size of the raycast