I’ve been working my ai script, for some reason it doesn’t move at all. There arent any errors printed except for line 116.
local NightMareAI = script.Parent
local humanoid = NightMareAI.Humanoid
local hrp = NightMareAI.HumanoidRootPart
local pathfinding = game:GetService("PathfindingService")
local players = {}
local alerted = NightMareAI["Stats/Values"].Alerted.Value
local radius = NightMareAI["Stats/Values"].Radius.Value
local waypoints = workspace.LoopPoints
local hipheight = NightMareAI.Configuration.Values.Config.Body.HipHeight.Value
NightMareAI.Humanoid.HipHeight = hipheight
--local path = pathfinding:CreatePath(path)
--for _, pathpos in pairs(waypoints:GetChildren()) do
-- path:ComputeAsync(hrp.Position, pathpos.Position)
--- humanoid:MoveTo(pathpos.Position)
-- humanoid.MoveToFinished:Wait()
--return path
--end
--}
local NightMareAI = script.Parent
local humanoid = NightMareAI.Humanoid
local hrp = NightMareAI.HumanoidRootPart
local pathfinding = game:GetService("PathfindingService")
local players = {}
local alerted = NightMareAI["Stats/Values"].Alerted.Value
local radius = NightMareAI["Stats/Values"].Radius.Value
local waypoints = workspace.LoopPoints
local lastpos
local pathparams = {
["AgentHeight"] = 10,
["AgentRadius"] = 4,
["AgentCanJump"] = true
}
local path = pathfinding:CreatePath(pathparams)
local function findTarget()
local players = game.Players:GetPlayers()
local maxDistance = radius
local nearestTarget
for i, player in pairs(players) do
if player.Character then
local target = player.Character
local distance = (hrp.Position - target.HumanoidRootPart.Position).Magnitude
if distance < maxDistance then
nearestTarget = target
maxDistance = distance
end
end
end
return nearestTarget
end
local function getPath(destination)
local path = pathfinding:CreatePath(pathparams)
path:ComputeAsync(hrp.Position, destination.Position)
return path
end
local function attack(target)
print("Attacking target:", target)
local distance = (hrp.Position - target.HumanoidRootPart.Position).Magnitude
local debounce = false
if distance > 5 then
humanoid:MoveTo(target.HumanoidRootPart.Position)
else
if debounce == false then
debounce = true
target.Humanoid.Health -= 10
print("Target's health:", target.Humanoid.Health)
task.wait(0.5)
debounce = false
end
end
end
local function walkTo(destination)
local path = getPath(destination)
if path.Status == Enum.PathStatus.Success then
for i, waypoint in pairs(path:GetWaypoints()) do
path.Blocked:Connect(function()
path:Destroy()
end)
if lastPos then
humanoid:MoveTo(lastPos)
humanoid.MoveToFinished:Wait()
lastPos = nil
break
else
humanoid:MoveTo(waypoint.Position)
humanoid.MoveToFinished:Wait()
end
local target = findTarget()
if target and target.Humanoid.Health > 0 then
lastPos = target.HumanoidRootPart.Position
attack(target)
break
end
end
else
print("Failed to find path to destination")
return
end
end
local function patrol()
print("Patrolling")
local randomNum = math.random(1, #waypoints:GetChildren())
walkTo(waypoints:GetChildren()[randomNum])
end
while true do
patrol()
wait(0.2)
end