Stop NPC from getting to closed?
How do I keep my NPC it's called police car and I want it to keep it's distance away from player. It can chased players down but I want it not to get too close to player cars.
01 | local larm = script.Parent:FindFirstChild( "Left Arm" ) |
02 | local rarm = script.Parent:FindFirstChild( "Right Arm" ) |
04 | function findNearestTorso(pos) |
05 | local list = game.Workspace:children() |
13 | if (temp 2. className = = "Model" ) and (temp 2 ~ = script.Parent) then |
14 | temp = temp 2 :findFirstChild( "Right Arm" ) |
15 | human = temp 2 :findFirstChild( "Target" ) |
16 | if (temp ~ = nil ) and (human ~ = nil ) and (human.Health > 0 ) then |
17 | if (temp.Position - pos).magnitude < dist then |
19 | dist = (temp.Position - pos).magnitude |
31 | wait(math.random( 1 , 5 )) |
32 | local target = findNearestTorso(script.Parent.Torso.Position) |
34 | script.Parent.Humanoid.Script.Disabled = false |
35 | script.Parent.Humanoid:MoveTo(target.Position, target, - 10 ) |
37 | script.Parent.Humanoid.Script.Disabled = true |