This script below will tell you all players in the client's view. This is done by using the :WorldToScreenPoint(Vector3)
method of the camera.
02 | local Players = game:GetService 'Players' |
03 | local RunService = game:GetService 'RunService' |
05 | repeat RunService.RenderStepped:wait() until Players.LocalPlayer and Players.LocalPlayer.Character and workspace.CurrentCamera |
07 | local camera = workspace.CurrentCamera |
08 | local player = Players.LocalPlayer |
09 | local character = player.Character |
13 | for i,v in next ,Players:GetPlayers() do |
21 | function getPlayersInView(t) |
24 | if v and v:IsA( "Player" ) and v.Character then |
25 | local torso = v.Character:FindFirstChild 'Torso' |
27 | local screenCords,IsInView = camera:WorldToScreenPoint(torso.Position) |
39 | local playersInView = getPlayersInView(getPlayers()) |
40 | if #playersInView > = 1 then |
41 | for i,v in next ,playersInView do |
45 | print ( "No players in view" ) |