I have two NPC's down on the level and they attack eachother as soon as I run it.
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 = 20 |
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" ) |
I have found the problem, in the scripting I said "findnearesttorso" but I don't know any other way of doing this.
Is there any way I can keep NPC's from attacking eachother but attack players?
Okay. I modified the script. All you have to do is change the name of the Humanoid to NPC (Including caps). This will probably break your other scripts. But they can be fixed by changing one word.
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 = 20 |
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" ) |
Not entirely sure of what the NPCs do to the player or each other. I need some more information like: Do the NPCs hurt when touching each other? Do NPCs battle other NPCs? Etc. Anyways, changing the humanoid is recommended, but if you have a variety of NPCs which it seems that you do, have another if statement at line 13. For example, within the NPC you can change something that distinguishes it like a string value, or a body color, or a script name.
Ex): if (temp2.className == "Model") and (temp2 ~= script.Parent) and FindFirstChild:("Scriptname/BodyColor/StringValue").Value/Name/BrickColor == "Name/Value/Color" then