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.
01 | local larm = script.Parent:FindFirstChild( "Left Arm" ) |
02 | local rarm = script.Parent:FindFirstChild( "Right Arm" ) |
03 |
04 | function 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 temp 2 = nil |
11 | for x = 1 , #list do |
12 | temp 2 = list [ x ] |
13 | if (temp 2. className = = "Model" ) and (temp 2 ~ = script.Parent) then |
14 | temp = temp 2 :findFirstChild( "Torso" ) |
15 | human = temp 2 :findFirstChild( "Humanoid" ) |
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).