-- / Functions / --

RagdollModule.SetupRagdoll = function(Character)
	for _, Joint in pairs(Character:GetDescendants()) do
		if Joint:IsA("Motor6D") then
			local A0 = Instance.new("Attachment")
			local A1 = Instance.new("Attachment")

			A0.Parent = Joint.Part0
			A1.Parent = Joint.Part1

			A0.CFrame = Joint.C0
			A1.CFrame = Joint.C1

			local BallSocketConstraint = Instance.new("BallSocketConstraint")
			BallSocketConstraint.Parent = Joint.Parent
			BallSocketConstraint.Enabled = false
			BallSocketConstraint.Attachment0 = A0
			BallSocketConstraint.Attachment1 = A1

		end
	end
end

RagdollModule.Ragdoll = function(Character)
	for _, CharacterObject in pairs(Character:GetDescendants()) do
		if CharacterObject:IsA("Motor6D") then
			local Joint = CharacterObject

			Joint:Destroy()

		elseif CharacterObject:IsA("BallSocketConstraint") then
			local BallSocketConstraint = CharacterObject

			BallSocketConstraint.Enabled = true

		elseif CharacterObject.Name == "Head" then
			if CharacterObject:IsA("BasePart") then				
				local Head = CharacterObject
				local HRP = Character:WaitForChild("HumanoidRootPart")

				Head.CanCollide = true

				local HeadWeld = Instance.new("WeldConstraint")
				HeadWeld.Parent = Head
				HeadWeld.Part0 = Head
				HeadWeld.Part1 = HRP
			end
		end
	end
end
