So, a few weeks back I started making my pathfinding, it works great, only when it finally kills an enemy, it cant find any more enemies. I’ve narrowed it down to this finding function, help?
local function find()
local en
for i, v in pairs(workspace.BOTS.Enemies.Pirates:GetChildren()) do
if v then
if v:FindFirstChild("HumanoidRootPart") then
if (v.HumanoidRootPart.Position - script.Parent.HumanoidRootPart.Position).Magnitude < stuff.findrange and v.Humanoid.Health > 0 then
en = v.HumanoidRootPart
return en
end
end
end
end
for i, v in pairs(workspace.BOTS.Enemies.WaterBois:GetChildren()) do
if v then
if v:FindFirstChild("HumanoidRootPart") then
if (v.HumanoidRootPart.Position - script.Parent.HumanoidRootPart.Position).Magnitude < stuff.findrange and v.Humanoid.Health > 0 then
en = v.HumanoidRootPart
return en
end
end
end
for i, v in pairs(workspace.BOTS.Enemies.Goblins:GetChildren()) do
if v then
if v:FindFirstChild("HumanoidRootPart") then
if (v.HumanoidRootPart.Position - script.Parent.HumanoidRootPart.Position).Magnitude < stuff.findrange and v.Humanoid.Health > 0 then
en = v.HumanoidRootPart
return en
end
end
end
end
for i, v in pairs(workspace.BOTS.Bad:GetChildren()) do
if v then
if v:FindFirstChild("HumanoidRootPart") then
if (v.HumanoidRootPart.Position - script.Parent.HumanoidRootPart.Position).Magnitude < stuff.findrange and v.Humanoid.Health > 0 then
en = v.HumanoidRootPart
return en
end
end
end
end
end
for i, v in pairs(game.Players:GetChildren()) do
if (v.Character.HumanoidRootPart.Position - script.Parent.HumanoidRootPart.Position).Magnitude < stuff.findrange and v.Character.Humanoid.Health > 0 then
if v.Character.HumanoidRootPart:FindFirstChild("Bad") then
en = v.Character.HumanoidRootPart
return en
end
end
end
end