If the title didn’t explain enough, I am making a SCP-173 and im using #Table to get the ammount of people looking at it:
That is the output and here is my code:
Client:
--[ VARIABLES/SETTINGS/SERVICES ]--
local Player = game.Players.LocalPlayer
local SCP173 = workspace.SCPs:WaitForChild("SCP173")
local Camera = workspace.CurrentCamera
local PlayersWhoCanSee173 = {}
local SCP173MainEvent = game.ReplicatedStorage.SCPEvents.SCP173.SCP173MainEvent
--[ SERVICES ]--
local RunService = game:GetService("RunService")
--[ MAIN ]--
function CanSee()
local _, WorldToScreenPoint = Camera:WorldToScreenPoint(SCP173.PrimaryPart.Position)
if WorldToScreenPoint then
return WorldToScreenPoint
else
return false
end
end
repeat wait() until Player.Character
while true do
RunService.Heartbeat:Wait()
local PlayerCanSee173 = CanSee()
if PlayerCanSee173 == true then
if table.find(PlayersWhoCanSee173, Player.Name) == nil then
table.insert(PlayersWhoCanSee173, Player.Name)
print(PlayersWhoCanSee173)
end
SCP173MainEvent:FireServer(PlayersWhoCanSee173)
else
local PlayerInList = table.find(PlayersWhoCanSee173, Player.Name)
table.remove(PlayersWhoCanSee173, PlayerInList)
SCP173MainEvent:FireServer(PlayersWhoCanSee173)
end
end
Server:
--[ VARIABLES/SERVICES ]--
local SCP173MainEvent = game.ReplicatedStorage.SCPEvents.SCP173.SCP173MainEvent
local PathfindingService = game:GetService("PathfindingService")
local TravelDebounce = false
--[ SETTINGS ]--
local Settings = {
Range = 150,
TravelDebounceTime = 0.04,
Damage = math.huge,
}
SCP173MainEvent.OnServerEvent:Connect(function(Player, Args)
print(Args)
local AmntOfPlayers = #Args
print(AmntOfPlayers)
if AmntOfPlayers == 0 then
local Distance = (Player.Character.HumanoidRootPart.Position - script.Parent.HumanoidRootPart.Position).Magnitude
if Distance <= Settings.Range then
local Path = PathfindingService:CreatePath()
Path:ComputeAsync(script.Parent.HumanoidRootPart.Position, Player.Character.HumanoidRootPart.Position)
local Waypoints = Path:GetWaypoints()
if Path.Status == Enum.PathStatus.Success then
if TravelDebounce == false then
for Index, Waypoint in pairs(Waypoints) do
TravelDebounce = true
local LookAt = CFrame.lookAt(script.Parent.HumanoidRootPart.Position, Player.Character.HumanoidRootPart.Position)
script.Parent:SetPrimaryPartCFrame(LookAt)
script.Parent:MoveTo(Waypoint.Position)
wait(Settings.TravelDebounceTime)
TravelDebounce = false
end
end
end
end
end
end)