local zombieHumanoid = script.Parent.Humanoid
local function findTarget()
local agroDistance = 100
local target = nil
for i, v in pairs(game.Workspace:GetChildren()) do
local human = v:FindFirstChild("Humanoid")
local torso = v:FindFirstChild("Torso")
if human and torso and v ~= script.Parent then
--Check distance
if (zombieTorso.Position - torso.Position).magnitude < agroDistance then
agroDistance = (zombieTorso.Position - torso.Position).magnitude
target = torso
end
end
end
return target
end
while wait(1) do
local torso = findTarget()
if torso then
zombieTorso:MoveTo(torso.Position)
end
end
local zombieHumanoid: Humanoid = script.Parent:FindFirstChildOfClass("Humanoid")
if not zombieHumanoid then
print("The humanoid doesn't exist. This script will create one now.")
zombieHumanoid = Instance.new("Humanoid")
zombieHumanoid.Parent = script.Parent
end
local function findTarget()
local agroDistance = 100
local target = nil
for i, v in pairs(game.Workspace:GetChildren()) do
local human = v:FindFirstChild("Humanoid")
local torso = v:FindFirstChild("Torso")
if human and torso and v ~= script.Parent then
--Check distance
if (zombieTorso.Position - torso.Position).magnitude < agroDistance then
agroDistance = (zombieTorso.Position - torso.Position).magnitude
target = torso
end
end
end
return target
end
while task.wait(1) do
local torso = findTarget()
if torso then
zombieHumanoid:MoveTo(torso.Position)
end
end
Let me know if this works! I basically added detection for if there is no Humanoid inside of the zombie yet. If no Humanoid is found, it will create one then.
I defined zombie torso at the top in the actual script but it cut out on the forum for some reason. I tried out the print and torso and it didn’t work T_T
I tried it out on a r6 character in game and it worked! Then I tried it out in game and it didn’t follow. After I tried it out on a r16 character and it didn’t work. It works on r6 characters but not r16 characters. (I also changed the torso to human root part and it still didn’t work)