I was following with a tutorial from TheDevKing on Magnitude. Here is the code:
local ZombieRoot = script.Parent.HumanoidRootPart
local ZombieHumanoid = script.Parent.Humanoid
local function findTarget()
local agroDistance = 100
for i, v in pairs(game.Workspace:GetChildren()) do
local Root = v:FindFirstChild("HumanoidRootPart")
local Humanoid = v:FindFirstChild("Humanoid")
if Root and Humanoid and v ~= nil then
if (ZombieRoot.Position - Root.Position).Magnitude < agroDistance then
target = v
end
end
end
return target
end
while wait(1) do
local Target = findTarget()
if Target ~= nil then
print("Found Target!")
ZombieHumanoid:MoveTo(target.HumanoidRootPart.Position)
end
end
There are no errors, but for some reason the zombie does not move to the target.
I also put two characters right beside the zombie to see if it would run the print function and it did but for some reason it did not move to the character.
I'm not sure if something else in my script is wrong or I used the Humanoid:MoveTo() function incorrectly. Please help me out if you what's wrong with my script. Thanks!
