local zombieTorso = script.Parent.Torso
local zombieHum = 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
zombieHum:MoveTo(Torso.Position)
end
end
The script is inside the npc ^^
Im trying to make an npc to chase another npc
It dint give me any errors
any help will be appreciated
I had this issue for a while, it would only return ‘0’ if I printed it. [check this before you try anything, if it returns a correct value dont edit it]
For some reason putting a CalculateMagnitude(PointA, PointB) function into a module script solved it? Still unsure as to why.