Detect if multiple people are looking at object

I made a script where if you don’t look at something it comes after you but if multiple people look at it, it bugs out like crazy.

Local Script:


local function IsVisible()
	-- LocalScript

	local partToCheck = workspace.SomePart
	local camera = workspace.CurrentCamera

	-- Check if on screen:
	local vector, inViewport = camera:WorldToViewportPoint(partToCheck.Position)
	local onScreen = inViewport and vector.Z > 0

	-- Raycast outward:
	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)

	-- Final check:
	local isVisible = onScreen and not raycastResult

	return isVisible
end

while true do
	task.wait()
	local isVisible = IsVisible()
	if isVisible then
		print("visible")
		game.ReplicatedStorage.Scp173:FireServer("Visible")
		game.ReplicatedStorage.Scp173Extras:FireServer("Visible")
		workspace.SomePart.IsSeen.Value = true
	else
		print("not visible")
		game.ReplicatedStorage.Scp173:FireServer("UnVisible")
		game.ReplicatedStorage.Scp173Extras:FireServer("UnVisible")
		workspace.SomePart.IsSeen.Value = false
	end
end

Ive tried using values as you can see but it still doesn’t work. Any help is appreciated
Server Script:


game.ReplicatedStorage.Scp173.OnServerEvent:Connect(function(player, statement)

	
	local part = game.Workspace.SomePart
	local lookpart = player.Character.HumanoidRootPart
	if statement == "UnVisible" and workspace.SomePart.IsSeen.Value == false then
		part.CFrame = CFrame.new(part.Position, Vector3.new(lookpart.Position.X, part.Position.Y, lookpart.Position.Z));
		part.CFrame = part.CFrame * CFrame.new(0, 0, -1) 
		
	elseif statement == "Visible" then
		
		
	
	end
end)


game.ReplicatedStorage.Scp173Extras.OnServerEvent:Connect(function(player, statement)
	while true do
		wait()
		if statement == "UnVisible" then
			workspace.SomePart.IsSeen.Value = false
		elseif statement == "Visible" then
			workspace.SomePart.IsSeen.Value = true
		end
	end
end)

you can just make the server script fire a event to all players then the local scripts sends the result if they are looking at it or not.
if you want a better way to detect if a part is visible to the player try this: