Why does network ownership keep changing even after setting setnetworkerownershipauto to false?

I have a pathfinding bot and it was working fine so I tried to fix a few bugs and make it smoother. But no matter what the network ownership keeps changing to the server and then client repeatedly. Any way to fix this?

function pathfind(target)
	local path = pathfindingService:CreatePath()
	path:ComputeAsync(humanoidRootPart.Position, target.Position)
	local waypoints = path:GetWaypoints()
	if path.Status == Enum.PathStatus.Success then
		for _, waypoint in ipairs(waypoints) do
			if waypoint.Action == Enum.PathWaypointAction.Jump then
				humanoid.Jump = true
			end
			humanoid:MoveTo(waypoints[3].Position)
			humanoidRootPart:SetNetworkOwner(game.Players:GetPlayerFromCharacter(target.Parent))
			humanoidRootPart:SetNetworkOwnershipAuto(false)
			if checkSight(target) then
				repeat
					wait()
					humanoid:MoveTo(target.Position)
					if target == nil or target.Parent == nil or target.Parent.Humanoid == nil or target.Parent.Humanoid.Health < 1 or humanoid.Health < 1 then
						break
					end
				until not checkSight(target)
				humanoidRootPart:SetNetworkOwner(game.Players:GetPlayerFromCharacter(target.Parent))
				humanoidRootPart:SetNetworkOwnershipAuto(false)
				break
			end
			humanoid.MoveToFinished:Wait()
		end
	end
end
2 Likes

BasePart:SetNetworkOwnershipAuto() essentially resets the network ownership as if you had never set it at all (and it doesn’t take arguments, so the false you provide is just being ignored). What you’re doing here is setting the network owner, then immediately resetting it. When you use BasePart:SetNetworkOwner(), it automatically prevents ownership from changing, so just remove the call to BasePart:SetNetworkOwnershipAuto(), and it should work.

3 Likes

This seems to have fixed the problem but now the bot moves to a waypoint, stops for a second, and moves to the next

Sometimes the bot completely stops moving for a few seconds

When they are in the player’s sight, or when it can’t see the player?