script.Parent.HumanoidRootPart:SetNetworkOwner(nil)
script.Parent.PrimaryPart:SetNetworkOwner(nil)
task.wait(1)
local players = game:GetService("Players")
local distance
local pfs = game:GetService("PathfindingService")
local function nearestPlayer()
for _, player in ipairs(players:GetPlayers()) do
local distance = (script.Parent.HumanoidRootPart.Position - player.Character.PrimaryPart.Position).Magnitude
local distanceMax = math.clamp(distance, 0, 100)
if distance > 100 then
local path = pfs:CreatePath({
AgentHeight = 5;
AgentRadius = 2;
AgentCanJump = false;
AgentCanClimb = false
})
path:ComputeAsync(script.Parent.HumanoidRootPart.CFrame, player.Character.HumanoidRootPart.CFrame)
local waypoints = path:GetWaypoints()
for _, waypoint in ipairs(waypoints) do
script.Parent.Humanoid:MoveTo(waypoint.Position)
end
end
end
end
while task.wait() do nearestPlayer() end
So the problem seems to come from this part ```lua
local distance = (script.Parent.HumanoidRootPart.Position - player.Character.HumanoidRootPart.Position).Magnitude