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

How do i make sure the NPC hunts down the closest Humanoid?

Asked by 3 years ago

My current script lets the NPC hunt the player who joined last, the NPC doesnt change target until that person leaves. I need to script it so that the NPC hunts the player who is closest, i tried to work it out myself with IntValues. Please someone help me!

01function getHumanoid(model)
02    for _, v in pairs(model:GetChildren()) do
03        if v:IsA'Humanoid' then
04            return v
05        end
06    end
07end
08 
09 
10local ai = script.Parent
11local human = getHumanoid(ai)
12local hroot = ai.HumanoidRootPart
13local zspeed = hroot.Velocity.magnitude
14 
15 
View all 61 lines...

Answer this question