Attempted to index nil with parent

Im trying to make a ragdoll but it doesn’t go away when you respawn
(the nil is personbody)

local humanoid = script.Parent:WaitForChild('Humanoid')
local person = script.Parent

humanoid.BreakJointsOnDeath = false

humanoid.Died:Connect(function()
	local plr = game.Players:GetPlayerFromCharacter(script.Parent)
	for index,joint in pairs(script.Parent:GetDescendants()) do
		if joint:IsA('Motor6D') then
			local socket = Instance.new("BallSocketConstraint")
			local a1 = Instance.new("Attachment")
			local a2 = Instance.new("Attachment")
			a1.Parent = joint.Part0
			a2.Parent = joint.Part1
			socket.Parent = joint.Parent
			socket.Attachment0 = a1
			socket.Attachment1 = a2
			a1.CFrame = joint.C0
			a2.CFrame = joint.C1
			socket.LimitsEnabled = true
			socket.TwistLimitsEnabled = true
			joint:Destroy()
			local personbody = person:Clone()
			personbody.Parent = workspace
			personbody.Position = person
			personbody.Anchored = true
			personbody.CanCollide = true
		end
	end
end)

There are a lot of references to the property “Parent” which line is the error occurring at?

Is personbody archiveable? I think that’s important.