I am making a zombie AI but it seems that when it kills me it no longer chases anyone. Please help as I can not figure it out.
Here is the script:
01 | torso = script.Parent.Torso |
02 | range = 50 |
03 | armDmg = 5 |
04 | torDmg = 10 |
05 | target = nil |
06 |
07 | function findNearestTarget() |
08 | plrs = game.Players:GetChildren() |
09 | for i,plr in ipairs (plrs) do |
10 | if plr.Character ~ = nil then |
11 | if plr.Character:findFirstChild( "Humanoid" ) and plr.Character.Humanoid.Health> 0 then |
12 | tor = plr.Character.Torso |
13 | if target ~ = nil then |
14 | if (torso.Position-tor.Position).magnitude < (torso.Position-target.Torso.Position).magnitude then |
15 | print (plr.Name.. " is in range" ) |
Well this script does work and it does chase people after it has killed you, I tested it using your script, if you place another scripted humanoid then the zombie will automatically chase it, if you want the zombie to chase people as quickly as possible then increase the range the zombie can follow you (maybe 80 or 100), I noticed the distance you put was quite low. Please accept the answer if it helped, if it didn't then post a comment explaining why.