Ragdoll Toggled By Boolean

how would i go about making this ragdoll script toggled by a boolean value

I’ve tried but im not really a scripting genius.

There is a folder that holds the constraints

local humanoid = script.Parent:WaitForChild("Humanoid")
humanoid.BreakJointsOnDeath = false
humanoid.Died:Connect(function()
	local motor = Instance.new("Motor6D")
	--Head
	local tatla = Instance.new("Attachment")
	local tatra = Instance.new("Attachment")	
	local athea = Instance.new("Attachment")
	local ath = Instance.new("Attachment")
	local atla = Instance.new("Attachment")
	local atra = Instance.new("Attachment")
	local socketH = script.Parent.BSCs.Head
	local socketLA = script.Parent.BSCs["Left Arm"]
	local socketRA = script.Parent.BSCs["Right Arm"]
	ath.Name = "HeadA"
	athea.Name = "TorsoA2"
	ath.Position = Vector3.new(0, -0.5,0)
	ath.Orientation = Vector3.new(0,0,90)
	ath.Parent = script.Parent.Head
	athea.Position = Vector3.new(0,1,0)
	athea.Orientation = Vector3.new(0,0,90)
	athea.Parent = script.Parent.Torso
	socketH.Attachment0 = script.Parent.Torso.TorsoA2
	socketH.Attachment1 = script.Parent.Head.HeadA
	--Left Arm
	atla.Name = "LeftArmA"
	tatla.Name = "TorsoA1"
	atla.Position = Vector3.new(0, 1,0)
	atla.Orientation = Vector3.new(0,180,0)
	atla.Parent = script.Parent["Left Arm"]
	tatla.Position = Vector3.new(-1.5,1,0)
	tatla.Orientation = Vector3.new(0,180,0)
	tatla.Parent = script.Parent.Torso
	socketLA.Attachment0 = script.Parent.Torso.TorsoA1
	socketLA.Attachment1 = script.Parent["Left Arm"].LeftArmA
	--Right Arm
	atra.Name = "RightArmA"
	tatra.Name = "TorsoA5"
	atra.Position = Vector3.new(0, 1,0)
	atra.Orientation = Vector3.new(0,180,0)
	atra.Parent = script.Parent["Right Arm"]
	tatra.Position = Vector3.new(1.5,1,0)
	tatra.Orientation = Vector3.new(0,180,0)
	tatra.Parent = script.Parent.Torso
	socketRA.Attachment0 = script.Parent.Torso.TorsoA5
	socketRA.Attachment1 = script.Parent["Right Arm"].RightArmA
	--Right Leg
		local socketRL = script.Parent.BSCs["Right Leg"]
		local socketLL = script.Parent.BSCs["Left Leg"]
		local atrl = Instance.new("Attachment")
		local atll = Instance.new("Attachment")
		local tatrl = Instance.new("Attachment")
		local tatll = Instance.new("Attachment")
	atrl.Name = "RightLegA"
	tatrl.Name = "TorsoA3"
	atrl.Position = Vector3.new(0, 1,0)
	atrl.Orientation = Vector3.new(0,180,180)
	atrl.Parent = script.Parent["Right Leg"]
	tatrl.Position = Vector3.new(0.5,-1,0)
	tatrl.Orientation = Vector3.new(0,-90,0)
	tatrl.Parent = script.Parent.Torso
	socketRL.Attachment0 = script.Parent.Torso.TorsoA3
	socketRL.Attachment1 = script.Parent["Right Leg"].RightLegA
	--Left Leg
	atll.Name = "LeftLegA"
	tatll.Name = "TorsoA4"
	atll.Position = Vector3.new(0, 1,0)
	atll.Orientation = Vector3.new(0,180,180)
	atll.Parent = script.Parent["Left Leg"]
	tatll.Position = Vector3.new(-0.5,-1,0)
	tatll.Orientation = Vector3.new(0,-90,0)
	tatll.Parent = script.Parent.Torso
	socketLL.Attachment0 = script.Parent.Torso.TorsoA4
	socketLL.Attachment1 = script.Parent["Left Leg"].LeftLegA
	for i,v in pairs(script.Parent.Torso:GetChildren()) do
		if v:IsA("Motor6D") then
			v:Destroy()
			 end
	end
	end)

I strongly recommend using a Attribute to toggle someones ragdoll, if they have died; simply clone the character and ragdoll that instead so the normal player can respawn and the ragdoll can disappear when you decide for it to.

Click here to learn about attributes.