How to make an NPC do something when a character walks IN FRONT of it?
Im trying to remake a Notoriety guard, and ALL i need is a way to find out how to print "Detected" (easy) but when a player or the character i mean walkes IN FORNT of it? I tried making an accesory with part that is transparent, (now its not becasue im testing) and this script didnt work:
01 | local SearchDistance = 10000 |
03 | local NPC = script.Parent |
04 | local HRP = NPC.HumanoidRootPart |
05 | local Humanoid = NPC:FindFirstChildOfClass( "Humanoid" ) |
07 | local function getNearestPlayer() |
08 | local playerDistances = { } |
10 | for i, player in pairs (game.Players:GetPlayers()) do |
12 | local distance = player:DistanceFromCharacter(HRP.Position) |
23 | if #playerDistances > = 1 then |
33 | for i, dataTable in pairs (playerDistances) do |
34 | local player = dataTable [ 1 ] |
35 | local distance = dataTable [ 2 ] |
36 | if player and distance then |
38 | if i = = 1 and distance < SearchDistance then |
46 | if HRP and Humanoid.Health > 0 then |
48 | local nearestPlayer = getNearestPlayer() |
49 | if nearestPlayer and nearestPlayer.Character.Masked.Value = = true then |
50 | game.Workspace.guard.sight.Handle.Touched:Connect( function (c) |
52 | script.Parent.Torso.Anchored = false |
pay attention to
01 | if HRP and Humanoid.Health > 0 then |
03 | local nearestPlayer = getNearestPlayer() |
04 | if nearestPlayer and nearestPlayer.Character.Masked.Value = = true then |
05 | game.Workspace.guard.sight.Handle.Touched:Connect( function (c) |
07 | script.Parent.Torso.Anchored = false |
it doesnt print anything, i tried script.Parent which is the actual model /NPC, it say parent is NIL!?!?!???
please help