So I was watching TheDevKing’s magnitude tutorial and he was making a script that makes a zombie walk around aimlessly and when a player is within range it starts chasing them. Everything was working perfectly for him but for me, nothing was even happening, not even any errors in output. I’m not sure if it’s because the tutorial is from 2019, but I need some help.
Script:
local zombieTorso = script.Parent.Torso
local zombieHumanoid = 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
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
zombieHumanoid:MoveTo(torso.Position)
else
zombieHumanoid:MoveTo(zombieTorso.Position + Vector3.new(math.random(-50, 50), 0, math.random(-50, 50)))
end
end