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