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