I tried SetNetworkOwner() on my NPC whenever it moves because when a player is near him the NPC then will start lagging and its movement will become choppy, but the problem is that SetNetworkOwner is not making any difference for some reason. even though I tried checking if it runs the code or not and it was running perfectly fine.
The main code of the first movement of my NPC:
local function MoveNPC(chosenWaypoint)
local success, errorMessage = pcall(function()
path:ComputeAsync(humanoidRootPart.Position,chosenWaypoint.Value)
end)
if success and path.Status == Enum.PathStatus.Success then
blockedConnection = path.Blocked:Connect(function(blockedWaypointIndex)
if blockedWaypointIndex >= nextWaypointIndex then
blockedConnection:Disconnect()
MoveNPC(chosenWaypoint)
end
end)
waypoints = path:GetWaypoints()
-- the main part of the code
for _,part in pairs(npc:GetChildren()) do
if part:IsA("BasePart") and part:CanSetNetworkOwnership() then
part:SetNetworkOwner(nil)
end
end
--==================================================
nextWaypointIndex = 2
humanoid:MoveTo(waypoints[nextWaypointIndex].Position)
require(game.ServerScriptService.StoreScripts.StoreModules.RestockNpcModule).Move(reachedConnection,humanoid,nextWaypointIndex,waypoints,walkAnim,blockedConnection
,GrabBoxOrientations,chosenWaypoint,humanoidRootPart,TweenIO,idle1,idle2,path,grabbingBoxAnim,boxHoldAnim,RestockWaypoints,npc,RestockOrientations
,boxReleasing,organizingShelves)
end
end