function findNearestTorso(pos)
local list = game.Workspace:children()
local torso = nil
local dist = 15 --attack distance
local temp = nil
human = nil
local temp2 = nil
local monster = nil
for x = 1, #list do
temp2 = list[x]
if (temp2.className == "Model") and (temp2 ~= script.Parent) then
temp = temp2:findFirstChild("HumanoidRootPart")
human = temp2:findFirstChild("Blue")
monster = temp2:findFirstChild("Reddy") --name of monster value --made by tvelok
if (temp ~= nil) and (human ~= nil) and (human.Health > 0) and (monster == nil) then
if (temp.Position - pos).magnitude < dist then
torso = temp
dist = (temp.Position - pos).magnitude
end
end
end
end
end
while true do
wait(1) --attack reload
local target = findNearestTorso(script.Parent.HumanoidRootPart.Position)
if target ~= nil then
human.Health = human.Health - 1 --attack damage
end
end
I tried to mold an old script into a script to make two NPCs from different teams fight each other. This script works on players but not other humanoids.
Other things that could help lead to the answer:
The two NPC's Humanoids are named 'Red' and 'Blue', with this script belonging to the 'Red'.
The script works on players, but not other humanoids.
The NPCs both have HumanoidRootParts and Torsos.

1 comment
That's not a solution.