I have a constant while wait() loop calling on a "update" function. This is the part that is causing whatever error this is. This is just a snip it of the code. The problem im having is the pathfinding is creating WAY to many waypoints in certain situations. I have the visible waypoints in there just for testing. There will be properly spaced waypoints then it will just place hundreds of them and the ai will walkto them in a very slow stuttering way. I cant pinpoint why exactly. There isnt multiple paths being created, the waypoints update when they reach a point. Looks something like this ; O O O O OOOOOOOOO O O O

Im real bad at writing questions like this because i've never really ran into something i couldnt figure out with time. But this just feels like a pathfinding error itself.

If i can post pictures ill post an example of it. And any more code you might need.

	elseif (v["TargetPart"].Position - model.HumanoidRootPart.Position).magnitude > v["Range"] 	then 
				v["See"] = false
				if model then
					if v["inMotion"] and not v["WalkToPoint"] and v["Can"] then
						print 'found new path commencing'
						local waypoints = v["Path"]:GetWaypoints()
						
						for _, waypoint in pairs(waypoints) do
							local part = Instance.new("Part")
							part.Shape = "Ball"
							part.Material = "Neon"
							part.Size = Vector3.new(0.6, 0.6, 0.6)
							part.Position = waypoint.Position
							part.Anchored = true
							part.CanCollide = false
							part.Parent = game.Workspace
							
							game.Debris:AddItem(part,0.2)
						end
						
						--print( v["CurrentWaypoint"],#waypoints)
						if v["CurrentWaypoint"] >= #waypoints then
							print 'waypoints failed.'
							Reset(v)
							v["inMotion"] = false
						else
							v["CurrentWaypoint"] = v["CurrentWaypoint"] + 1
							v["WalkToPoint"] = waypoints[v.CurrentWaypoint]
						end
					elseif v["inMotion"] and v["WalkToPoint"] then
						print 'walking to point'
						model.Humanoid:MoveTo(v["WalkToPoint"].Position)
						if v["WalkToPoint"] ~= nil and v["WalkToPoint"].Action ~= nil and v["WalkToPoint"].Action == Enum.PathWaypointAction.Jump then
							if (v["TargetPart"].Position.Y - model.HumanoidRootPart.Position.Y) > 2 then
								model.Humanoid.Jump = true
							end
						end
						v["Fix"] = v["Fix"] + 1
						if (v["WalkToPoint"].Position - (model.HumanoidRootPart.Position - Vector3.new(0,model.HumanoidRootPart.Size.Y,0))).magnitude <= 1.5 then
							v["Fix"] = 0 
							v["WalkToPoint"] = nil
							print 'Point reached'
						elseif v["Fix"] >= 30 then
							Reset(v)
							print 'broke xd'
							model.Humanoid.Jump = true
							v["inMotion"] = false
						end
					elseif not v["inMotion"] and v["Can"] then --cant see target
						print 'No path created'
						--treat like a reset()--
						Reset(v)
						v["Can"] = false
						v["inMotion"] = true
						--delay(math.random(1,3),function()
							if model and model:findFirstChild("HumanoidRootPart") then
								v["Path"] = pathService:CreatePath()
								v["Path"]:ComputeAsync(model.HumanoidRootPart.Position, v["TargetPart"].Position)
								wait()
								v["Can"] = true
							end
						--end)
					end
				end
			end

1 comment

0

bump