Your enemyDetected
only returns the first enemy it finds, not every single enemy visible!
To fix this, I made it return a Table of all matches, rather than the first match:
01 | local _FindCharacter = script.Parent.Parent.Parent.Parent.Parent.Character |
02 | function ClearMiniMap() |
03 | for i,v in pairs (script.Parent:GetChildren()) do |
04 | if v:IsA( "Frame" ) and v.Name = = "Enemy" or v.Name = = "Neutral" or v.Name = = "Friendly" then |
10 | function enemyDetected(pos) |
13 | for _, xlist in ipairs (workspace:GetChildren()) |
14 | if xlist:IsA( "Model" ) and xlist ~ = script.Parent then |
15 | local islarm = xlist:FindFirstChild( "Left Arm" ) |
16 | local ishuman = xlist:FindFirstChild( "Enemy" ) |
17 | local torso = xlist:FindFirstChild( "Torso" ) |
18 | if torso and islarm and ishuman then |
19 | If (torso.Position - pos).magnitude < 50 then |
20 | table.insert(detected, torso) |
31 | if _FindCharacter ~ = nil then |
32 | local targets = enemyDetected(_FindCharacter.Torso) |
33 | for _, target in ipairs (targets) do |
35 | if target.Detected = = true then |
36 | local CopyEnemy = script.Parent.Storage.Enemy:Clone() |
37 | CopyEnemy.Parent = script.Parent |
40 | CopyEnemy.Position = UDim 2. new( 0 , (_FindCharacter.Torso.Position.x - target.Position.x), |
41 | 0 , (_FindCharacter.Torso.Position.z - target.Position.z)) |