My npcs are supposed to move and kill other people/npcs but after they kill 1 dummy the won’t move anymore. They also won’t target players, only the dummy. Does anyone here know what’s wrong with my script?
ServerScript: --placed inside the model of npc
local RomanRoot = script.Parent.HumanoidRootPart
local RomanHumanoid = script.Parent.Humanoid
local Model = script.Parent
local ss = game:GetService("ServerStorage")
local collectionService = game:GetService("CollectionService")
while wait() do
local function findenemy()
local aggro = 6000
local target = nil
local dmgrange = 7
for i, v in pairs(game.Workspace:GetChildren()) do
if collectionService:HasTag(v.Parent, "Iskandar") then
print(v.Parent.Name)
return
else do
local human = v:FindFirstChild("Humanoid")
local root = v:FindFirstChild("HumanoidRootPart")
if human and root and v ~= script.Parent then
if v.Humanoid.Health > 0 then
if v.Name ~= "RomanSoldier" then
if (RomanRoot.Position - root.Position).Magnitude < aggro then
aggro = (RomanRoot.Position - root.Position).Magnitude
target = root
if (RomanRoot.Position - root.Position).Magnitude <= dmgrange then
human.Health = human.Health - 15
end
end
end
end
return target
end
end
end
end
end
while wait(1) do
local torso = findenemy()
if torso then
RomanHumanoid:MoveTo(torso.Position)
end
end
end