Ok, so I tried to make a zombie move to the player within 100 magnitude, but it doesnt move to the target and doesn’t do anything at all, I tried to debug it by re-writting the code, printing at specific positions, etc… But it didn’t work. (Output also says no errors)
Script here:
local zombie = script.Parent
local zombietorso = script.Parent:WaitForChild(“Torso”)
local zombiehumanoid = script.Parent:WaitForChild(“Humanoid”)
local function checkTarget()
local target = nil
local aggrodist = 100
for i, v in pairs(workspace:GetChildren()) do
local hum = v:FindFirstChild(“Humanoid”)
local torso = v:FindFirstChild(“Torso”)
if torso and hum and (zombietorso.Position - torso.Position).magnitude < aggrodist and hum.Health > 0 and v ~= zombie then
aggrodist = (zombietorso.Position - torso.Position).magnitude
target = torso
end
end
return target
end
while wait(1) do
local torso = checkTarget()
if torso then
print(“Working!”)
zombiehumanoid:MoveTo(torso.Position)
print(“b”)
end
end