I have a big problem, my NPC don't stop attacking each other! I changed the humanoid name and the scripts but it doesn't work! What I have to do!
This is the first NPC script.
local TwitcherMainScript = script;
local Twitcher = TwitcherMainScript.Parent;
local Head = Twitcher:FindFirstChild("Head");
local HumanoidRootPart = Twitcher:FindFirstChild("HumanoidRootPart");
local LeftArm = Twitcher:FindFirstChild("Left Arm");
local LeftLeg = Twitcher:FindFirstChild("Left Leg");
local RightArm = Twitcher:FindFirstChild("Right Arm");
local RightLeg = Twitcher:FindFirstChild("Right Leg");
local Torso = Twitcher:FindFirstChild("Torso");
local TwitcherHumanoid = Twitcher:FindFirstChild("ColdBloodedKiller");
local AxeIsOut = false;
local AxeEnabled = true;
local TwitcherAttackAnimation = TwitcherHumanoid:LoadAnimation(Twitcher.CloseAttackAnim);
local TwitcherAlertSounds = {Head.zo_alert10,Head.zo_alert20,Head.zo_alert30};
local TwitcherAttackSounds = {Head.zo_attack1,Head.zo_attack2};
local TwitcherClawStrikeSounds = {Head.zo_clawstrike1,Head.zo_clawstrike2,Head.zo_clawstrike3};
local TwitcherPainSounds = {Head.zo_pain1,Head.zo_pain2};
repeat Wait(0) until TwitcherHumanoid ~= nil
repeat TwitcherHumanoid:TakeDamage(10) TwitcherHumanoid.Health = TwitcherHumanoid.MaxHealth Wait(0) until TwitcherHumanoid.Health == TwitcherHumanoid.MaxHealth
local SpawnForceField = Instance.new("ForceField")
SpawnForceField.Name = "SpawnForceField"
SpawnForceField.Parent = Twitcher
function FollowTarget(TargetHumanoid, TargetTorso)
if not TargetHumanoid or not TargetHumanoid.Parent or TargetHumanoid.Health == 0 or not TargetTorso or not TargetTorso.Parent then
return
end
local TwitcherRadiusXAxis = math.random(-2,2)
local TwitcherRadiusYAxis = math.random(-2,2)
local TwitcherRadiusZAxis = math.random(-2,2)
TwitcherHumanoid:MoveTo(TargetTorso.Position+Vector3.new(TwitcherRadiusXAxis,TwitcherRadiusYAxis,TwitcherRadiusZAxis), TargetTorso)
end
function ThunderAttack(TargetHumanoid, TargetTorso)
if not TargetHumanoid or not TargetHumanoid.Parent or TargetHumanoid.Health == 0 or not TargetTorso or not TargetTorso.Parent then
return
end
local TwitcherDamage = 10
TwitcherAttackSounds[math.random(1,#TwitcherAttackSounds)]:Play()
TwitcherHumanoid.WalkSpeed = 0
Wait(0.3)
TwitcherClawStrikeSounds[math.random(1,#TwitcherClawStrikeSounds)]:Play()
if TargetTorso~=nil and(Torso.Position-TargetTorso.Position).magnitude<=7 then
TargetHumanoid:TakeDamage(TwitcherDamage)
end
TwitcherAttackAnimation:Play();
TwitcherAttackAnimation:AdjustSpeed(1.5);
Wait(0.4)
TwitcherAttackAnimation:Play();
TwitcherAttackAnimation:AdjustSpeed(1.5);
TwitcherClawStrikeSounds[math.random(1,#TwitcherClawStrikeSounds)]:Play()
if TargetTorso~=nil and(Torso.Position-TargetTorso.Position).magnitude<=7 then
TargetHumanoid:TakeDamage(TwitcherDamage)
end
Wait(0.21)
TwitcherHumanoid.WalkSpeed = 10
end
function FindTarget()
local ClosestCharacter
local ClosestHumanoid = nil
local ClosestTorso = nil
local ClosestTorsoDistance = 99999e99999
for TargetCount, TargetModel in pairs(Game.Workspace:GetChildren()) do
if TargetModel:IsA("Model") and (TargetModel ~= Twitcher) and (TargetModel.Name ~= Twitcher.Name) and (TargetModel.Name ~= "Stranger") and (TargetModel.Name ~= "David Leatherhoff") and (TargetModel.Name ~= "HandCrab") and (TargetModel.Name ~= "GhostAbomination") then
if TargetModel:FindFirstChild("Humanoid")~=nil then
local humanoid = TargetModel:FindFirstChild("Humanoid")
local torso = TargetModel:FindFirstChild("Torso")
if torso ~= nil then
local TorsoDistance = (torso.Position - Torso.Position).magnitude
if humanoid and humanoid.Health > 0 and torso and TorsoDistance <= ClosestTorsoDistance then
ClosestCharacter = TargetModel
ClosestHumanoid = humanoid
ClosestTorso = torso
ClosestTorsoDistance = TorsoDistance
end
end
end
end
end
return ClosestCharacter, ClosestHumanoid, ClosestTorso
end
function FindTarget2()
local ClosestCharacter
local ClosestHumanoid = nil
local ClosestTorso = nil
local ClosestTorsoDistance = 5
for TargetCount, TargetModel in pairs(Game.Workspace:GetChildren()) do
if TargetModel:IsA("Model") and (TargetModel ~= Twitcher) and (TargetModel.Name ~= Twitcher.Name) and (TargetModel.Name ~= "Stranger") and (TargetModel.Name ~= "David Leatherhoff") and (TargetModel.Name ~= "HandCrab") and (TargetModel.Name ~= "GhostAbomination") then
if TargetModel:FindFirstChild("Humanoid")~=nil then
local humanoid = TargetModel:FindFirstChild("Humanoid")
local torso = TargetModel:FindFirstChild("Torso")
if torso ~= nil then
local TorsoDistance = (torso.Position - Torso.Position).magnitude
if humanoid and humanoid.Health > 0 and torso and TorsoDistance <= ClosestTorsoDistance then
ClosestCharacter = TargetModel
ClosestHumanoid = humanoid
ClosestTorso = torso
ClosestTorsoDistance = TorsoDistance
end
end
end
end
end
return ClosestCharacter, ClosestHumanoid, ClosestTorso
end
Wait(5)
for DavidHealthCheck = 1,5 do
TwitcherHumanoid.Health = TwitcherHumanoid.MaxHealth
Wait(0)
end
HumanoidRootPart.Anchored = false
SpawnForceField:Destroy()
function HurtSound(HumanoidData)
if TwitcherHumanoid.Health<0 or TwitcherHumanoid.Health==0 then return end
TwitcherPainSounds[math.random(1,#TwitcherPainSounds)]:Play()
TwitcherPainSounds[math.random(1,#TwitcherPainSounds)].Pitch = 1 + (math.random() * 0.07)
end
TwitcherHumanoid.HealthChanged:connect(HurtSound)
while Wait(0) do
if TwitcherHumanoid.Health == 0 or TwitcherHumanoid.Health < 0 then
TwitcherHumanoid.WalkSpeed = 0
script.Disabled = true
Wait(5)
Twitcher:Destroy()
end
if TwitcherHumanoid.Sit==true then
TwitcherHumanoid.Jump=false
end
if TwitcherHumanoid.PlatformStand==true then
TwitcherHumanoid.Jump=false
end
local character, humanoid, torso = FindTarget()
if character and character.Parent and humanoid and humanoid.Parent and torso and torso.Parent then
FollowTarget(humanoid, torso)
end
local character, humanoid, torso = FindTarget2()
if character and character.Parent and humanoid and humanoid.Parent and torso and torso.Parent then
ThunderAttack(humanoid, torso)
end
local TwitcherAlertSound = (math.random(1,500))
if TwitcherAlertSound == 100 then
TwitcherAlertSounds[math.random(1,#TwitcherAlertSounds)].Pitch = 1 + (math.random() * 0.07)
TwitcherAlertSounds[math.random(1,#TwitcherAlertSounds)]:Play()
end
end

6 comments
There is another one but I can't post it!
Did you make this yourself?
yes
How don't you know how to do that then?
I don't know how you made your script but you can easily verify if it's a player using for index, plr in pairs(game.Players:GetPlayers()) do if plr.Name == Target then IsPlayer = true end end or something like that
Your code is a mess to read. Please indent. And, somewhere in your FindTarget functions is where the problem is. Only post that part of your code because the other stuff are irrelevant.