AI ignoring pathfinding modifiers

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)

It seems to work when I add the “hum.MoveToFinished:Wait()” back, but then the AI stops frequently.

Every time you use pathfinding with a pairs loop, you have to add the MoveToFinished:Wait(). Your path is generating perfectly fine. Each time the AI tries to path to one waypoint, the loop restarts and that path is overlapped by the next waypoint, since it does not wait until it reaches the waypoint. So the AI just goes straight to the last waypoint. So add the hum.MoveToFnished:Wait() back. You could try setting doing part:SetNetworkOwner(nil) to make it stutter less.

Thanks. Sadly SetNetworkOwner doesn’t work because it is all client sided.

You could just set it in a separate script, but I’m not sure if it would work.

@rfisty Heey Nice project mate your working on but do u know what Ai means ?

Yes. Artificial intelligence. Why?

It wouldn’t because I spawn the model through the client.

Why are you doing this through client? Is it because you want the monster to spawn for each player and chase them individually?

Yes. It’s an obby so every player should have their own for it to be fair.

@rfisty Ok mate just checking cuz the last player was talking about ai and he didn’t know what it means so that’s why I asked yea mate

Why not just have a script inside the model to set the network ownership?