How can I make a zombie go to the player with Humanoid:MoveTo() ?
Asked by
4 years ago Edited 4 years ago
I was following with a tutorial from TheDevKing on Magnitude. Here is the code:
01 | local ZombieRoot = script.Parent.HumanoidRootPart |
02 | local ZombieHumanoid = script.Parent.Humanoid |
04 | local function findTarget() |
05 | local agroDistance = 100 |
06 | for i, v in pairs (game.Workspace:GetChildren()) do |
07 | local Root = v:FindFirstChild( "HumanoidRootPart" ) |
08 | local Humanoid = v:FindFirstChild( "Humanoid" ) |
10 | if Root and Humanoid and v ~ = nil then |
11 | if (ZombieRoot.Position - Root.Position).Magnitude < agroDistance then |
20 | local Target = findTarget() |
23 | print ( "Found Target!" ) |
24 | ZombieHumanoid:MoveTo(target.HumanoidRootPart.Position) |
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!