I have a horror pathfinding AI that is supposed to chase after players. The only issue is that it runs into walls and gets stuck. The path that it should take is shown in the video, along with the path the AI is actually taking. I am using Pathfinding modifiers.
Video:
Script:
repeat wait() until game.Players.LocalPlayer.Character
local endpart = game.Workspace.EndPart1
local startpart = game.Workspace.StartPart1
local spawned = false
startpart.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if hit.Parent.Name == game.Players.LocalPlayer.Name then
if spawned == false then
spawned = true
game.Players.LocalPlayer.PlayerGui.Main.RUN.Visible = true
local clone = script.BACKROOMS:Clone()
clone.Parent = game.Workspace
clone.ChaseSound.Playing = true
local pathservice = game:GetService("PathfindingService")
local path = pathservice:CreatePath()
local hum,hrp = game.Workspace.BACKROOMS.Humanoid, game.Workspace.BACKROOMS.HumanoidRootPart
local EndingPoint = game.Players.LocalPlayer.Character.HumanoidRootPart
local activeID
local agentParameters = {
AgentCanJump = false,
Costs = {
DangerZone = math.huge
}
}
game.Players.LocalPlayer.Character.Humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
activeID = newproxy()
local currentID = activeID
local newPath = pathservice:CreatePath(agentParameters)
newPath:ComputeAsync(hrp.Position, EndingPoint.Position)
for i,v in pairs(newPath:GetWaypoints()) do
hum:MoveTo(v.Position)
--hum.MoveToFinished:Wait()
if activeID ~= currentID then
break
end
end
end)
end
end
end
end)
endpart.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if hit.Parent.Name == game.Players.LocalPlayer.Name then
if game.Workspace:FindFirstChild("BACKROOMS") then
game.Workspace.BACKROOMS:Destroy()
spawned = false
game.Players.LocalPlayer.PlayerGui.Main.RUN.Visible = false
game.Workspace.BACKROOMS.ChaseSound.Playing = false
end
end
end
end)
game.Players.LocalPlayer.Character.Humanoid.Died:Connect(function()
if game.Workspace:FindFirstChild("BACKROOMS") then
game.Workspace.BACKROOMS:Destroy()
spawned = false
game.Players.LocalPlayer.PlayerGui.Main.RUN.Visible = false
game.Workspace.BACKROOMS.ChaseSound.Playing = false
end
end)