Network ownership messes up NPC ragdolls

Ive found plenty of posts on this but none of them seem to fix it. But what ive been trying to do is make a ragdoll script that can be called by anyscript via a module script

I made the inside of a module script so that it can be required by anyscript to ragdoll something which works fine if the server owns the NPC but if the player gets too close it breaks them, ive tried setting networkowner to nil but it imidietly changes back to the player.

ive tried disabling humanoid.AutomaticScalingEnabled which hasnt worked either

local charEvents = {}

--Ragdolls the given player
function charEvents.Ragdoll(char: Model?,stunTime: number?)
	local hum: Humanoid = char.Humanoid
	hum.RequiresNeck = false
	print(hum)
	for i,v in char.Torso:GetChildren() do
		if v:IsA("Motor6D") then
			local ballConstraint = Instance.new("BallSocketConstraint",char.Torso)
			ballConstraint.Name = v.Name
			ballConstraint.LimitsEnabled = true
			ballConstraint.TwistLimitsEnabled = true
			local att0 = Instance.new("Attachment")
			local att1 = Instance.new("Attachment")
			if string.find(v.Part1.Name,"Leg") then
				att0.Name = "ragAtt0"
				att0.Parent = v.Part1
				att0.Position += Vector3.new(0,1,0)
				att1.Name = "ragAtt1"
				att1.Parent = char.Torso
				att1.WorldPosition = att0.WorldPosition
				ballConstraint.Parent = char.Torso
				ballConstraint.Attachment0 = att0
				ballConstraint.Attachment1 = att1
			elseif string.find(v.Part1.Name,"Arm") then
				att0.Name = "ragAtt0"
				att0.Parent = v.Part1
				att0.Position += Vector3.new(0,1,0)
				att1.Name = "ragAtt1"
				att1.Parent = char.Torso
				att1.WorldPosition = att0.WorldPosition
				ballConstraint.Parent = char.Torso
				ballConstraint.Attachment0 = att0
				ballConstraint.Attachment1 = att1
			elseif v.Name == "Neck" then
				att0.Name = "ragAtt0"
				att0.Parent = v.Part1
				att0.Position -= Vector3.new(0,0.5,0)
				att1.Name = "ragAtt1"
				att1.Parent = char.Torso
				att1.WorldPosition = att0.WorldPosition
				ballConstraint.Parent = char.Torso
				ballConstraint.Attachment0 = att0
				ballConstraint.Attachment1 = att1
			end
			v.Enabled = false
		end
	end
	for i,v:BasePart in hum:GetDescendants() do
		if v:IsA("BasePart") then
			v:SetNetworkOwner(nil)
		end
	end
	local state = Enum.HumanoidStateType.Physics
	repeat
		hum:ChangeState(state)
		task.wait()
	until hum:GetState() == state
	wait(stunTime)
	for i,v in char:GetDescendants() do
		if v:IsA("Motor6D") then
			v.Enabled = true
		elseif v:IsA("BallSocketConstraint") or v:IsA("Attachment") and (v.Name == "ragAtt0" or v.Name == "ragAtt1") then
			v:Destroy()
		end
	end
	task.wait()
	hum.RequiresNeck = true
	local state = Enum.HumanoidStateType.GettingUp
	repeat
		hum:ChangeState(state)
		task.wait()
	until hum:GetState() == state
end

return charEvents

im not really sure what to do as i need to be able to ragdoll NPC’s for testing weapons etc

Do the NPCs follow the player by any chance if you get close to them?