Ragdolling characters causes their arms to stick to the torso and unragdolling makes them fling up

So i have this server-sided ragdoll script:

function module.Ragdoll(character:Model, ragdollmiktari)
	
	if character:GetAttribute("Ragdolled") == true then return end
	local hum = character:FindFirstChild("Humanoid")::Humanoid
	if not hum then return end
	
	if character:HasTag("PlayerChar") then
		RagdollRemote:FireClient(ps:GetPlayerFromCharacter(character), ragdollmiktari) --for ui handling
	end
	
	for i, joint in pairs(character:GetDescendants()) do
		if joint:IsA("Motor6D") then
			joint.Enabled = false
		elseif joint:IsA("BasePart") and joint.Name == "Collide" then
			joint.CanCollide = true
		elseif joint:IsA("BallSocketConstraint") then
			joint.Enabled = true
		end
	end
	
	hum.PlatformStand = true
	hum.AutoRotate = false
	
	character:SetAttribute("Ragdolled", true)
	
	hum:UnequipTools()
	
	UnequipConnections[character] = character.ChildAdded:Connect(function(child)
		hum:UnequipTools() --for unequiping tools, obviously
	end)
	
end

function module.UnRagdoll(character:Model)
	
	local hum = character:FindFirstChild("Humanoid")::Humanoid
	if not hum then return end
	
	if UnequipConnections[character] then
		UnequipConnections[character]:Disconnect()
		UnequipConnections[character] = nil
	end
	
	character:SetAttribute("Ragdolled", false)
	
	for i, joint in pairs(character:GetDescendants()) do
		if joint:IsA("Motor6D") then
			joint.Enabled = true
		elseif joint:IsA("BallSocketConstraint") then
			joint.Enabled = false
		elseif joint:IsA("BasePart") and joint.Name == "Collide" then
			joint.CanCollide = false
		end
	end
	
	hum.PlatformStand = false
	hum.AutoRotate = true
end

And this script for set up. Its being called on CharacterAdded event + when dummies are created:

function module.BuildCollisionParts(char: Model)
	for _, v in pairs(char:GetChildren()) do
		if v:IsA("BasePart") and v.Name ~= "HumanoidRootPart" then
			local p = Instance.new("Part")
			p.Size = v.Size
			p.CFrame = v.CFrame
			p.Anchored = false
			p.CanCollide = false
			p.Massless = true
			p.Transparency = 1
			p.Name = "Collide"
			p.Parent = char

			local weld = Instance.new("WeldConstraint")
			weld.Part0 = v
			weld.Part1 = p
			weld.Parent = p
		end
	end
end


	for i, joint in pairs(char:GetDescendants()) do
		
		if joint:IsA("Motor6D") then
			local socket = Instance.new("BallSocketConstraint")
			
			if joint.Name == "Neck" then
				print("thats a neck")
				socket.Name = "BallSocketConstraintHead"
			end
			
			local att0 = Instance.new("Attachment", joint.Part0)
			local att1 = Instance.new("Attachment", joint.Part1)

			att0.CFrame = joint.C0
			att1.CFrame = joint.C1

			att0.Name = "att0"
			att1.Name = "att1"

			socket.Attachment0 = att0
			socket.Attachment1 = att1
			socket.TwistLimitsEnabled = true
			socket.LimitsEnabled = true

			socket.UpperAngle = 45 

			socket.TwistLowerAngle = -30 
			socket.TwistUpperAngle = 30 
			
			socket.Enabled = false
			
			socket.Parent = joint.Parent
			
		end
		
	end

On a server script:

RagdollModule.UnRagdoll(char)

Arms:

Unragdolling: (it doesnt always happen)

Do anyone knows how do i fix these?

Well you see, this code is a mess, to say the least.

First of all, you’re using the RagdollRemote Event FireSystem to send the Ragdollmiktari to the client? Why do you need to do this?

Secondly, your Unragdoll code isn’t running, which is why it doesn’t work.

Thirdly, you don’t have any comments in your code so how can anyone understand if you dont do that?

It’s for UIs, doesnt have anything to do with topic

I think its clear but you might be right. Let me just edit

What do you mean isnt running? It IS running i just didnt see a need to share the script that calls the unragdoll function.

I edited the post, is it clear enough now?

thanks yeah thats a little clear but I’m asking why you are even doing that in the first place?
to me, it just seems like over-engineering, in fact, I have never seen anyone do this in my life, and I’ve been scripting for 8 years almost a decade

What do you mean by that? Ragdolling? Im kinda confused rn which part of the code is over-engineering?

what I see here is just a bunch of overcomplicated systems you have a ragdollmiktari that you are sending for some reason you are manually disabling constraints, and you don’t even use a simple Boolean. I just cannot wrap my head around why anybody would ever write code like this.

Forget about Ragdollmiktari, its some ui thing and has nothing to do with the ragdoll mechanic. And yea i will get code shorter and simpler by taking

for i, joint in pairs(character:GetDescendants()) do
		if joint:IsA("Motor6D") then
			joint.Enabled = true
		elseif joint:IsA("BallSocketConstraint") then
			joint.Enabled = false
		elseif joint:IsA("BasePart") and joint.Name == "Collide" then
			joint.CanCollide = false
		end
	end
	
	hum.PlatformStand = false
	hum.AutoRotate = true

this part into a seperate function etc, but im talking about the functionalty here. Whats might really be causing the issue i mentioned on the post?

well first of all id use a different approach completely buts thats just me.

the issue you are probably having is that when a constrant is disabled, it doesnt updated the CFrame
until the next physics tick
therefore if you manually set the cframe of the constraint when it is disabled it will override the cframe from the previopus physics tick and the character will not ragdoll.

xDeltaXen have been giving false information and trolling on several posts. I would take their replies suspiciously, and assume they are not being truthful.

Wow, thanks for the warning. Do you have any advice to fix the issue?