Enemy cannot calculate a path even when it should be able to

What do you want to achieve?
I want to make an enemy follow a player.
What is the issue?
The enemy cannot generate a path
What solutions have you tried so far?
I tried making enemy AgentRadius and AgentHeight 1 and I tried to change the collision settings because it worked before and it stopped working once I changed them.

PS, everything in my game worked before but it stopped once I switched computers.

spawn(function()
	while true do
		for _, enemy in pairs(attackEnemies) do
			print("clujju") --Prints "clujju"
			print(enemy:GetChildren())
			local specificEnemyData = enemyData[enemy.enemyId.Value]
			local closestCharacter = nil
			local distance = specificEnemyData.aggroRange
			local range = enemy.range
			for _, player in pairs(players:GetChildren()) do
				local character = player.Character
				if character then
					local humanoidRootPart = character.HumanoidRootPart
					local magnitude = (range.Position - humanoidRootPart.Position).magnitude
					if magnitude < distance then 
						closestCharacter = character
						distance = magnitude
					end
				end
			end
			if closestCharacter then
				print("crong") --Prints "crong"
				if distance < specificEnemyData.notFollowDistance then

				else
					print("pachot") --Prints "pachot"
					local path = pathfindingService:CreatePath(specificEnemyData.pathParameters) --specificEnemyData.pathParameters = 	{AgentRadius = 1,AgentHeight = 1,AgentCanJump = false,WaypointSpacing = 3,Costs = {deathZones = math.huge,possibleZones = 10} 
					table.insert(attackEnemyPaths, {path, enemy.bossModel, closestCharacter})
					local pathIndex = #attackEnemyPaths
					local success, errorMessage = pcall(function()
						path:ComputeAsync(enemy.range.Position, closestCharacter.HumanoidRootPart.Position)
					end)
					print("lokomoko;", success, path.Status) --Prints "lokomoko; true Enum.PathStatus.NoPath"
					if success then and path.Status == Enum.PathStatus.Success then
						print("LAMA") --Doesn't print because Enum.PathStatus.NoPath
						local waypoints
						local currentWaypoint = 0
						waypoints = path:GetWaypoints()
						local blockedConnection = path.Blocked:Connect(function(blockedWaypoint)
							if blockedWaypoint >= currentWaypoint + 1 then
								path:ComputeAsync(enemy.range.Position, closestCharacter.HumanoidRootPart.Position)
								waypoints = path:GetWaypoints()
							end
						end)
						print("prizzaafg") --Doesn't print because of if above
						while true do
							currentWaypoint = currentWaypoint + 1
							print("kuja")
							if waypoints[currentWaypoint] ~= nil then
								print("pringa") --Doesn't print because of if above
								enemy.bossModel.Humanoid:MoveTo(waypoints[currentWaypoint].Position)
							else
								blockedConnection:Disconnect()
								table.remove(attackEnemyPaths, pathIndex)
								break
							end
							enemy.bossModel.Humanoid.MoveToFinished:Wait()
						end
					else
						return errorMessage
					end
				end
			end
		end
		wait(1)
	end
end)

spawn(function()
	while true do
		for _, enemyPathParameters in pairs(attackEnemyPaths) do
			print("rancan")
			local path = enemyPathParameters[1]
			local enemy =  enemyPathParameters[2]
			local target =  enemyPathParameters[3]
			path:ComputeAsync(enemy.HumanoidRootPart.Position, target.HumanoidRootPart.Position)
		end
		wait(1)
	end
end)

Really appreciate some help. If you have any comments on optimizing, I’d love to hear those too. I’m pretty sure there’s a way to detect when a player moves but I can’t figure it out.

yesiss.wmv (2.8 MB)

1 Like