Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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:

01local ZombieRoot = script.Parent.HumanoidRootPart
02local ZombieHumanoid = script.Parent.Humanoid
03 
04local 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")
09 
10        if Root and Humanoid and v ~= nil then
11            if (ZombieRoot.Position - Root.Position).Magnitude < agroDistance then
12                target = v
13            end
14        end
15    end
View all 26 lines...

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!

1 answer

Log in to vote
0
Answered by 4 years ago

I found a solution but it wasn't really obvious. Instead of using the load character plugin, I just went to the tool box and used a free NPC model. I'm not really sure how it made a difference but for some reason it worked.

Ad

Answer this question