Detect if player is looking at another player holding a specific iftem

Im trying to make a system to detect is a user is looking at another player who is holding a specific item, I want it to loop itself.

while 1 > 0 do
	for i, plr in pairs(game.Players:GetChildren()) do
		local partToCheck = plr.item.Handle
		local camera = workspace.CurrentCamera

		local vector, inViewport = camera:WorldToViewportPoint(partToCheck.Position)
		local onScreen = inViewport and vector.Z > 0

		local ray = camera:ViewportPointToRay(vector.X, vector.Y, 0)
		local raycastParams = RaycastParams.new()
		raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
		raycastParams.FilterDescendantsInstances = {partToCheck, game.Players.LocalPlayer.Character}
		local raycastResult = workspace:Raycast(ray.Origin, ray.Direction * 1000, raycastParams)

	
		local isVisible = onScreen and not raycastResult
		if isVisible then
		


			local ReplicatedStorage = game:GetService("ReplicatedStorage")

			local remoteEvent = ReplicatedStorage:WaitForChild("remoteEvent")
	
			game.Players.PlayerAdded:Connect(function(thisPlayer)
				local playerName = thisPlayer.Name
				print(playerName)
			remoteEvent:FireServer(playerName)

			end)
			

		end
	end
	end

Please could you find the issue and fix it

I don’t know how it works or you want your script to work, but target is gives you the object which is on the mouse pointer. You just have to check if the object is a Humanoid and there you have it

local Players = game:GetService("Players");
local localPlayer = Players.LocalPlayer;
local Mouse = localPlayer:GetMouse();

while(task.wait(0.5))do
	local Target = Mouse.Target;
	if(Target ~= nil and Target.Parent:FindFirstChild("Humanoid"))then
		if(Target.Parent:FindFirstChild(Tool Name))then
		end
	end
end