So all my npc does is rotate and howl slowly and I’m confused on why its not and the NPC I looked off of for the code does.
On a timeframe and I know the pathfinding method is deprecated not worried at all about that please just post the fix with what was wrong so I know for next time.
Moving Code
local Hum = script.Parent.Humanoid or script.Parent:WaitForChild('Humanoid')
local Path = game:GetService("PathfindingService")
local config = script.Parent.Configurations
local targetBots = false
local targetV = script.Parent:WaitForChild("Target")
function FindEnemies()
local Hums = {}
if targetBots then
local function Find(x)
for _,obj in pairs(x:GetChildren()) do
if obj:IsA("Model") then
if obj:FindFirstChild'Humanoid' and obj:FindFirstChild'HumanoidRootPart' and obj.Humanoid.Health > 0 and not obj:FindFirstChild'NPC' and not obj:FindFirstChild'ForceField' then
table.insert(Hums,obj.Humanoid)
end
end
Find(obj)
end
end
Find(workspace)
else
for _,v in pairs(game.Players:GetPlayers()) do
if v.Character and v.Character:FindFirstChild'HumanoidRootPart' and v.Character:FindFirstChild'Humanoid' and v.Character.Humanoid.Health > 0 and not v:FindFirstChild'ForceField' and not v.Character:FindFirstChild'AFK' then
table.insert(Hums, v.Character.Humanoid)
end
end
end
local closest,path,dist
for i,hum in pairs(Hums) do
local MyPath = Path:ComputeSmoothPathAsync(Hum.Parent.HumanoidRootPart.Position, hum.Parent.HumanoidRootPart.Position, 20)
if MyPath.Status ~= Enum.PathStatus.FailFinishNotEmpty then
local myDist = 0
local prev = Hum.Parent.HumanoidRootPart.Position
for _,point in pairs(MyPath:GetPointCoordinates()) do
myDist = myDist + (point-prev).magnitude
prev = point
end
if not dist or myDist < dist then
closest = Hum
path = MyPath
dist = myDist
end
end
end
return closest,path
end
function goToPos(loc)
Hum:MoveTo(loc)
local distance = (loc-Hum.Parent.HumanoidRootPart.Position).magnitude
local start = tick()
while distance > 4 do
if tick()-start > distance/Hum.WalkSpeed then
break
end
distance = (loc-Hum.Parent.HumanoidRootPart.Position).magnitude
wait()
end
end
while wait() do
local target,path = FindEnemies()
local didBreak = false
local targetStart
if target and Hum.Parent.HumanoidRootPart then
targetV.Value = target
targetStart = target.Parent.HumanoidRootPart.Position
roaming = false
local prev = Hum.Parent.HumanoidRootPart.Position
local points = path:GetPointCoordinates()
local s = #points > 1 and 2 or 1
for i = s,#points do
local point = points[i]
if didBreak then
break
end
if target and target.Parent.HumanoidRootPart and target.Health > 0 then
if (target.Parent.HumanoidRootPart.Position-targetStart).magnitude < 1.5 then
local pos = prev:lerp(point,.5)
local moveDir = ((pos - Hum.Parent.HumanoidRootPart.Position).unit * 2)
goToPos(prev:lerp(point,.5))
prev = point
end
else
didBreak = true
break
end
end
else
targetV.Value = nil
end
if not didBreak and targetStart then
goToPos(targetStart)
end
end
```
**Animate Code**
```Lua
local Hum = script.Parent.Humanoid or script.Parent:WaitForChild("Humanoid")
local Config = script.Parent.Configurations
local Pose = "Standing"
---Functions
function Walking(speed)
if speed > .5 then
local scale = 10
local Walk = Hum:LoadAnimation(Config.Walking)
Walk:Play()
Pose = "Running"
else
Pose = "idle"
if Pose == "idle" then
local idle = Hum:LoadAnimation(Config.Idle)
idle:Play()
end
end
end
function Dead()
Pose = "Died"
print'dead'
local noise = Config.Screech
noise.Volume = 10
noise:Play()
end
---Connections
Hum.Running:Connect(Walking)
Hum.Died:Connect(Dead)
Custom NPC Pic