Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does my NPC follow script has a problem?

Asked by 7 years ago

I want to create a crime game where if you commit a crime wanted is a boolvalue and it is in the humanoid. Wanted only activate if you commit a crime. When the police officers are spawned on the same area they attack each other, how can I stop this they kept on following each other if not they will follow me and I just want them to follow me without changing the humanoid name to something else cause I make a lot of weapons that involved players humanoid and that's a lot of work to do.

01local larm = script.Parent:FindFirstChild("Left Arm")
02local rarm = script.Parent:FindFirstChild("Right Arm")
03 
04function findNearestTorso(pos)
05    local list = game.Workspace:children()
06    local torso = nil
07    local dist = script.Distance.Value
08    local temp = nil
09    local human = nil
10    local temp2 = nil
11    for x = 1, #list do
12        temp2 = list[x]
13        if (temp2.className == "Model") and (temp2 ~= script.Parent) then
14            temp = temp2:findFirstChild("Torso")
15            human = temp2:findFirstChild("Humanoid")
View all 44 lines...
0
:GetChildren? User#20388 0 — 7y
0
^^ Michael_TheCreator 166 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

You appear to be trying to find a suitable target 2x! First when you call "findNearestTorso" (which needs to have code added to determine whether a model is a fellow police officer or not - ex, you could add a Folder/BoolValue/whatever with the name "PoliceOfficer" to police officer NPCs so that your script can tell difference), then again in lines 30+. The if checks on lines 32-33 should be moved to findNearestTorso and then the for loop on line 30 removed (keeping lines 34-35).

0
thanks FunimationStudioArt -14 — 7y
Ad

Answer this question