I have been working for half an hour and I need to figure this out Recently I was playing my game, and someone asked my why the zombies attack each other. So now I am trying to fix it. Every thing I know how to do does not seem to work. Here is the script:
local larm = script.Parent:FindFirstChild("HumanoidRootPart") local rarm = script.Parent:FindFirstChild("HumanoidRootPart") function findNearestTorso(pos) local list = game.Workspace:children() local torso = nil local dist = 35 local temp = nil local human = nil local temp2 = 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("Humanoid") if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then if (temp.Position - pos).magnitude < dist then if temp2:FindFirstChild("Folder") then print("He My friend") else torso = temp dist = (temp.Position - pos).magnitude end end end end end return torso end while true do wait(1) local target = findNearestTorso(script.Parent.HumanoidRootPart.Position) if target ~= nil then script.Parent.Humanoid:MoveTo(target.Position, target) end end
The script below assumes that all zombies are named zombie
local larm = script.Parent:FindFirstChild("HumanoidRootPart") local rarm = script.Parent:FindFirstChild("HumanoidRootPart") function findNearestTorso(pos) local list = game.Workspace:children() local torso = nil local dist = 35 local temp = nil local human = nil local temp2 = 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("Humanoid") if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then if (temp.Position - pos).magnitude < dist then if temp2:FindFirstChild("Folder") then print("He My friend") else torso = temp dist = (temp.Position - pos).magnitude end end end end end return torso end while true do wait(1) local target = findNearestTorso(script.Parent.HumanoidRootPart.Position) if target ~= nil then if target.Name ~= "zombie" then script.Parent.Humanoid:MoveTo(target.Position, target) end end end
Also this probably dosent work. I currently cant test in in studio seeing as im in school XD:D