local sets = script.Parent.Settings
local canJump = sets["Can the NPC jump when they hit a wall?"].Value
local distance = sets["Maximum Distance (In Studs)"].Value
local hrp = script.Parent:FindFirstChild("HumanoidRootPart")
local npcHumanoid = script.Parent:FindFirstChild("Humanoid")
local anim = script.idle
local track = script.Parent.Humanoid:WaitForChild("Animator"):LoadAnimation(anim)
local function Follow()
local target = nil
local shortestDistance = distance
for _, model in ipairs(workspace:GetChildren()) do
if model ~= script.Parent and model:FindFirstChild("Humanoid") and model:FindFirstChild("HumanoidRootPart") then
print("FOUND")
if model.Parent.Name == "camp2" then
print("----what")
local humanoid = model:WaitForChild("Humanoid")
if humanoid.Health > 0 then
print("NOTDEAD")
local targetHRP = model:WaitForChild("HumanoidRootPart")
local dist = (targetHRP.Position - hrp.Position).Magnitude
print("Distance: ", dist)
if dist <= shortestDistance then
print("CLOSEST")
shortestDistance = dist
target = targetHRP
end
else
print("o")
end
end
end
end
local mim = 3
if target then
print("kill")
npcHumanoid:MoveTo(target.Position)
npcHumanoid.MoveToFinished:Wait()
track:Play()
script.Parent.Threat.Value = true
script.Parent.bullie.Value = true
local distanceToTarget = (target.Position - hrp.Position).Magnitude
if distanceToTarget < mim then
print("toclose")
local directionAway = (hrp.Position - target.Position).Unit
local newPosition = hrp.Position * directionAway * mim
script.Parent.Humanoid.AutoRotate = false
npcHumanoid:MoveTo(newPosition)
wait(0.3)
script.Parent.Humanoid.AutoRotate = true
end
else
print("dead?") ---this line prints only when the npc is far or close to camp2 npc
script.Parent.Humanoid.AutoRotate = true
track:Stop()
end
end
while wait(0.1) do
Follow()
if canJump then
script.Parent.JumpScript.Disabled = false
end
end
so what the problem is script only prints dead? even if the npc is close to camp2 npc or far, it gives me no error or anything it just prints dead