Ragdoll physics help

Hiya devs, just question.
sometimes, not always and ic ant figure out the reasoning, the ragdoll with getup from its ragdolled state and start floating upwards?

function Ragdoller:Ragdoll(Character)
	if Character:FindFirstChild("Ragdolled") then return end
	if game.CollectionService:HasTag(Character, "IsRagdolled") then
		return
	end
	game.CollectionService:AddTag(Character, "IsRagdolled")

	spawn(function()
		for _,v in pairs(Character:GetChildren()) do
			if v.Name == "Blocking" then
				v:Destroy()
			end
		end
		givesound(Character)

	
	end)
	if not Character:FindFirstChild("Ragdolled") then
		local ragdollfolder = Instance.new("Folder")
		ragdollfolder.Name = "Ragdolled"
		ragdollfolder.Parent = Character
	end
	

	print("Ragdolling")
	
	
	Character.Humanoid.PlatformStand = true
	Character.Humanoid.Sit = true
	local Humanoid = Character.Humanoid

	Humanoid:ChangeState(Enum.HumanoidStateType.Ragdoll)

	Character.Humanoid.WalkSpeed = 0
	Character.Humanoid.AutoRotate = false
	Character.Humanoid.JumpPower = 0
	

	

	Character.Humanoid.PlatformStand = true
	Character.Humanoid.Sit = true
	local Humanoid = Character.Humanoid
	Character.Humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, false)
	Character.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Physics, true)
	Character.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
	Character.Humanoid:SetStateEnabled(Enum.HumanoidStateType.FallingDown, true)
	Character.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Ragdoll, true)
	Humanoid:ChangeState(Enum.HumanoidStateType.Ragdoll)

	Character.Humanoid.WalkSpeed = 0
	Character.Humanoid.AutoRotate = false
	Character.Humanoid.JumpPower = 0
	local leftarm = Character:WaitForChild("Left Arm")
	local rightrm = Character:WaitForChild("Right Arm")
	local leftleg = Character:WaitForChild("Left Leg")
	local rightleg = Character:WaitForChild("Right Leg")
	if Character.Torso:FindFirstChild("Left Hip") then
		Character.Torso:FindFirstChild("Left Hip").Enabled = false
		Character.Torso.CanCollide = true
		local head = Character.Head
		local attach0 = Instance.new("Attachment",Character.Torso)
		local attach1 = Instance.new("Attachment",Character["Left Leg"])
		attach0.CFrame = CFrame.new(-0.5, -1, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0)
		attach1.CFrame = CFrame.new(-0, 1, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0)
		attach0.Name = "BallAttachment"
		attach1.Name = "BallAttachment"
		local glue = IntNew("BallSocketConstraint", Character.Torso)
		glue.Attachment0 = attach0
		glue.Attachment1 = attach1
		glue.Name = "Left leg"	
		local collider = IntNew("Part", leftleg)
		collider.Name = "Collider"
		collider.Position = Vector3.new(0,999,0)
		collider.Size = Vector3.new(1.5, 1, 1)
		collider.Shape = "Block"
		collider.Massless = true
		local weld = IntNew("Weld", collider)
		weld.Part0 = leftleg
		weld.Part1 = collider
		weld.C0 = CFrame.new(0,-0.2,0) * CFrame.fromEulerAnglesXYZ(0, 0, math.pi/2)
		collider.TopSurface = "Smooth"
		collider.BottomSurface = "Smooth"
		collider.formFactor = "Symmetric"
		collider.Transparency = 1
		------------
		if Character.Torso:FindFirstChild("Right Hip") and Character.Torso:FindFirstChild("Right Shoulder") and Character.Torso:FindFirstChild("Left Hip") and Character.Torso:FindFirstChild("Left Shoulder")  then
			Character.Torso:FindFirstChild("Right Hip").Enabled = false
			local attach0 = Instance.new("Attachment",Character.Torso)
			local attach1 = Instance.new("Attachment",Character["Right Leg"])
			attach0.Name = "BallAttachment"
			attach1.Name = "BallAttachment"
			attach0.CFrame =	CFrame.new(0.5, -1, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0)
			attach1.CFrame = CFrame.new(0, 1, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0)
			local glue1 = IntNew("BallSocketConstraint", Character.Torso)
			glue1.Attachment0 = attach0
			glue1.Attachment1 = attach1
			glue1.Name = "Right leg"
			local collider1 = IntNew("Part", rightleg)
			collider1.Name = "Collider"
			collider1.Position = Vector3.new(0,9999,0)
			collider1.Size = Vector3.new(1.5, 1, 1)
			collider1.Massless = true
			collider1.Shape = "Block"
			local weld1 = IntNew("Weld", collider1)
			weld1.Part0 = rightleg
			weld1.Part1 = collider1
			weld1.C0 = CFrame.new(0,-0.2,0) * CFrame.fromEulerAnglesXYZ(0, 0, math.pi/2)
			collider1.TopSurface = "Smooth"
			collider1.BottomSurface = "Smooth"
			collider1.formFactor = "Symmetric"
			collider1.Transparency = 1
			------------
			Character.Torso:FindFirstChild("Right Shoulder").Enabled = false
			local attach0 = Instance.new("Attachment",Character.Torso)
			local attach1 = Instance.new("Attachment",Character["Right Arm"])
			attach0.Name = "BallAttachment"
			attach1.Name = "BallAttachment"
			attach0.CFrame =	CFrame.new(1.5, 0.5, 0, 0, 0, 1, 0, 1, 0, -1, 0, 0)
			attach1.CFrame = CFrame.new(0, 0.5, 0, 0, 0, 1, 0, 1, 0, -1, 0, 0)
			local glue11 = IntNew("BallSocketConstraint", Character.Torso)
			glue11.Attachment0 = attach0
			glue11.Attachment1 = attach1
			glue11.Name = "Right shoulder"
			local collider11 = IntNew("Part", rightrm)
			collider11.Name = "Collider"
			collider11.Position = Vector3.new(0,9999,0)
			collider11.Size = Vector3.new(1.8,1,1)
			collider11.Massless = true
			collider11.Shape = "Block"
			local weld11 = IntNew("Weld", collider11)
			weld11.Part0 = rightrm
			weld11.Part1 = collider11
			weld11.C0 = CFrame.new(0,-0.2,0) * CFrame.fromEulerAnglesXYZ(0, 0, math.pi/2)
			collider11.TopSurface = "Smooth"
			collider11.BottomSurface = "Smooth"
			collider11.formFactor = "Symmetric"
			collider11.Transparency = 1
			------------
			Character.Torso:FindFirstChild("Left Shoulder").Enabled = false
			local attach0 = Instance.new("Attachment",Character.Torso)
			local attach1 = Instance.new("Attachment",Character["Left Arm"])
			attach0.Name = "BallAttachment"
			attach1.Name = "BallAttachment"
			attach0.CFrame =	CFrame.new(-1.5, 0.5, 0, 0, 0, -1, 0, 1, 0, 1, 0, 0)
			attach1.CFrame = CFrame.new(0, 0.5, 0, 0, 0, -1, 0, 1, 0, 1, 0, 0)
			local glue111 = IntNew("BallSocketConstraint", Character.Torso)
			glue111.Attachment0 = attach0
			glue111.Attachment1 = attach1
			glue111.Name = "Left shoulder"
			local collider111 = IntNew("Part", leftarm)
			collider111.Name = "Collider"
			collider111.Position = Vector3.new(0,9999,0)
			collider111.Size = Vector3.new(1.5, 1, 1)
			collider111.Massless = true	
			collider111.Shape = "Block"
			local weld111 = IntNew("Weld", collider111)
			weld111.Part0 = leftarm
			weld111.Part1 = collider111
			weld111.C0 = CFrame.new(0,-0.2,0) * CFrame.fromEulerAnglesXYZ(0, 0, math.pi/2)
			collider111.TopSurface = "Smooth"
			collider111.BottomSurface = "Smooth"
			collider111.formFactor = "Symmetric"
			collider111.Transparency = 1
	--[[for i,v in pairs(Character:GetChildren()) do
		if v:IsA("Part") or v:IsA("MeshPart") or v:IsA("UnionOperation") then
			if v.CanCollide == false then
				v.CanCollide = true
				spawn(function()
					repeat wait() until Character.Ragdolled.Value == false
					v.CanCollide = false
				end)
			end
		end
	end]]
		end	
	end	
	
end


1 Like

I obviously don’t know about the mechanics of your game, BUT, I believe I found the answer to your problem

local Ragdoller = {}

function Ragdoller:Ragdoll(Character)
	if Character:FindFirstChild("Ragdolled") then return end
	
	if game.CollectionService:HasTag(Character, "IsRagdolled") then
		return
	end
	
	game.CollectionService:AddTag(Character, "IsRagdolled")

	spawn(function()
		for _,v in pairs(Character:GetChildren()) do
			if v.Name == "Blocking" then
				v:Destroy()
			end
		end
	end)
	
	-- givesound(Character) --// I deactivated here just to test out the ragdoll module
	
	if not Character:FindFirstChild("Ragdolled") then
		local ragdollfolder = Instance.new("Folder")
		ragdollfolder.Name = "Ragdolled"
		ragdollfolder.Parent = Character
	end
	
	print("Ragdolling")
	
	local Humanoid = Character:FindFirstChildWhichIsA("Humanoid")

	Humanoid.WalkSpeed = 0
	Humanoid.AutoRotate = false
	Humanoid.JumpPower = 0
	Humanoid.PlatformStand = true
	
	local RootPart = Character:FindFirstChild("HumanoidRootPart")

	if Humanoid:GetState() == Enum.HumanoidStateType.Jumping or Humanoid:GetState() == Enum.HumanoidStateType.Freefall then
		Humanoid:ChangeState(Enum.HumanoidStateType.FallingDown)
	end

	if RootPart then
		RootPart.AssemblyLinearVelocity = Vector3.new(RootPart.AssemblyLinearVelocity.X, 0, RootPart.AssemblyLinearVelocity.Z)
	end
	
	Humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, false)
	Humanoid:SetStateEnabled(Enum.HumanoidStateType.Physics, true)
	Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
	Humanoid:SetStateEnabled(Enum.HumanoidStateType.FallingDown, true)
	
	Humanoid.EvaluateStateMachine = false --// Dont remove this
	
	Humanoid.StateChanged:Connect(function(_, new)
		if new == Enum.HumanoidStateType.PlatformStanding then
			Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
		end
	end)
	
	local leftarm = Character:WaitForChild("Left Arm")
	local rightarm = Character:WaitForChild("Right Arm")
	local leftleg = Character:WaitForChild("Left Leg")
	local rightleg = Character:WaitForChild("Right Leg")
	local head = Character:WaitForChild("Head")
	
	if Character.Torso:FindFirstChild("Left Hip") then
		Character.Torso:FindFirstChild("Left Hip").Enabled = false
		Character.Torso.CanCollide = true

		if Character.Torso:FindFirstChild("Right Hip") and Character.Torso:FindFirstChild("Right Shoulder") and Character.Torso:FindFirstChild("Left Hip") and Character.Torso:FindFirstChild("Left Shoulder")  then
			Character.Torso:FindFirstChild("Right Hip").Enabled = false
			
			local attach0 = Instance.new("Attachment",Character.Torso)
			local attach1 = Instance.new("Attachment",Character.Head)

			attach0.CFrame = CFrame.new(-0.5, -1, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0)
			attach1.CFrame = CFrame.new(-0, 1, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0)
			attach0.Name = "BallAttachment"
			attach1.Name = "BallAttachment"

			local glue = Instance.new("BallSocketConstraint", Character.Torso)

			glue.Attachment0 = attach0
			glue.Attachment1 = attach1
			glue.Name = "Left leg"	

			local colliderHead = Instance.new("Part", head)

			colliderHead.Name = "_ColliderHead"
			colliderHead.Position = Vector3.new(0,999,0)
			colliderHead.Size = Vector3.new(1, 1, 1)
			colliderHead.Shape = "Block"
			colliderHead.Massless = true
			colliderHead.CanCollide = true

			local weld = Instance.new("Weld", colliderHead)

			weld.Part0 = head
			weld.Part1 = colliderHead
			weld.C0 = CFrame.new(0,0,0) * CFrame.fromEulerAnglesXYZ(0, 0, math.pi/2)

			colliderHead.TopSurface = "Smooth"
			colliderHead.BottomSurface = "Smooth"
			colliderHead.formFactor = "Symmetric"

			colliderHead.Transparency = 1 --// You can see here where the collider is positioned
			
			local attach0 = Instance.new("Attachment",Character.Torso)
			local attach1 = Instance.new("Attachment",Character["Left Leg"])

			attach0.CFrame = CFrame.new(-0.5, -1, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0)
			attach1.CFrame = CFrame.new(-0, 1, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0)
			attach0.Name = "BallAttachment"
			attach1.Name = "BallAttachment"
			
			local glue = Instance.new("BallSocketConstraint", Character.Torso)

			glue.Attachment0 = attach0
			glue.Attachment1 = attach1
			glue.Name = "Left leg"	

			local colliderLeftLeg = Instance.new("Part", leftleg)

			colliderLeftLeg.Name = "_ColliderLeftLeg"
			colliderLeftLeg.Position = Vector3.new(0,999,0)
			colliderLeftLeg.Size = Vector3.new(1, 1, 1)
			colliderLeftLeg.Shape = "Block"
			colliderLeftLeg.Massless = true
			colliderLeftLeg.CanCollide = true

			local weld = Instance.new("Weld", colliderLeftLeg)

			weld.Part0 = leftleg
			weld.Part1 = colliderLeftLeg
			weld.C0 = CFrame.new(0,0,0) * CFrame.fromEulerAnglesXYZ(0, 0, math.pi/2)

			colliderLeftLeg.TopSurface = "Smooth"
			colliderLeftLeg.BottomSurface = "Smooth"
			colliderLeftLeg.formFactor = "Symmetric"
			
			colliderLeftLeg.Transparency = 1 --// You can see here where the collider is positioned
			
			local attach0 = Instance.new("Attachment",Character.Torso)
			local attach1 = Instance.new("Attachment",Character["Right Leg"])
			
			attach0.Name = "BallAttachment"
			attach1.Name = "BallAttachment"
			
			attach0.CFrame =	CFrame.new(0.5, -1, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0)
			attach1.CFrame = CFrame.new(0, 1, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0)
			
			local glue1 = Instance.new("BallSocketConstraint", Character.Torso)
			
			glue1.Attachment0 = attach0
			glue1.Attachment1 = attach1
			
			glue1.Name = "Right leg"
			
			local colliderRightLeg = Instance.new("Part", rightleg)
			
			colliderRightLeg.Name = "_ColliderRightLeg"
			colliderRightLeg.Position = Vector3.new(0,9999,0)
			colliderRightLeg.Size = Vector3.new(1, 1, 1)
			colliderRightLeg.Massless = true
			colliderRightLeg.Shape = "Block"
			colliderRightLeg.CanCollide = true
			
			local weld1 = Instance.new("Weld", colliderRightLeg)
			
			weld1.Part0 = rightleg
			weld1.Part1 = colliderRightLeg
			
			weld1.C0 = CFrame.new(0,0,0) * CFrame.fromEulerAnglesXYZ(0, 0, math.pi/2)
			
			colliderRightLeg.TopSurface = "Smooth"
			colliderRightLeg.BottomSurface = "Smooth"
			colliderRightLeg.formFactor = "Symmetric"
			colliderRightLeg.Transparency = 1 --// You can see here where the collider is positioned
			
			Character.Torso:FindFirstChild("Right Shoulder").Enabled = false
			
			local attach0 = Instance.new("Attachment",Character.Torso)
			local attach1 = Instance.new("Attachment",Character["Right Arm"])
			
			attach0.Name = "BallAttachment"
			attach1.Name = "BallAttachment"
			
			attach0.CFrame =	CFrame.new(1.5, 0.5, 0, 0, 0, 1, 0, 1, 0, -1, 0, 0)
			attach1.CFrame = CFrame.new(0, 0.5, 0, 0, 0, 1, 0, 1, 0, -1, 0, 0)
			
			local glue11 = Instance.new("BallSocketConstraint", Character.Torso)
			
			glue11.Attachment0 = attach0
			glue11.Attachment1 = attach1
			
			glue11.Name = "Right shoulder"
			
			local colliderRightArm = Instance.new("Part", rightarm)
			
			colliderRightArm.Name = "_ColliderRightArm"
			colliderRightArm.Position = Vector3.new(0,9999,0)
			colliderRightArm.Size = Vector3.new(1, 1, 1)
			colliderRightArm.Shape = "Block"
			colliderRightArm.Massless = true
			colliderRightArm.CanCollide = true
			
			local weld11 = Instance.new("Weld", colliderRightArm)
			
			weld11.Part0 = rightarm
			weld11.Part1 = colliderRightArm
			
			weld11.C0 = CFrame.new(0,0,0) * CFrame.fromEulerAnglesXYZ(0, 0, math.pi/2)
			
			colliderRightArm.TopSurface = "Smooth"
			colliderRightArm.BottomSurface = "Smooth"
			colliderRightArm.formFactor = "Symmetric"
			colliderRightArm.Transparency = 1 --// You can see here where the collider is positioned
			
			Character.Torso:FindFirstChild("Left Shoulder").Enabled = false
			
			local attach0 = Instance.new("Attachment",Character.Torso)
			local attach1 = Instance.new("Attachment",Character["Left Arm"])
			
			attach0.Name = "BallAttachment"
			attach1.Name = "BallAttachment"
			
			attach0.CFrame =	CFrame.new(-1.5, 0.5, 0, 0, 0, -1, 0, 1, 0, 1, 0, 0)
			attach1.CFrame = CFrame.new(0, 0.5, 0, 0, 0, -1, 0, 1, 0, 1, 0, 0)
			
			local glue111 = Instance.new("BallSocketConstraint", Character.Torso)
			
			glue111.Attachment0 = attach0
			glue111.Attachment1 = attach1
			
			glue111.Name = "Left shoulder"
			
			local colliderLeftArm = Instance.new("Part", leftarm)
			
			colliderLeftArm.Name = "_ColliderLeftArm"
			colliderLeftArm.Position = Vector3.new(0,9999,0)
			colliderLeftArm.Size = Vector3.new(1, 1, 1)
			colliderLeftArm.Shape = "Block"
			colliderLeftArm.Massless = true
			colliderLeftArm.CanCollide = true
			
			local weld111 = Instance.new("Weld", colliderLeftArm)
			
			weld111.Part0 = leftarm
			weld111.Part1 = colliderLeftArm
			
			weld111.C0 = CFrame.new(0,0,0) * CFrame.fromEulerAnglesXYZ(0, 0, math.pi/2)
			
			colliderLeftArm.TopSurface = "Smooth"
			colliderLeftArm.BottomSurface = "Smooth"
			colliderLeftArm.formFactor = "Symmetric"
			colliderLeftArm.Transparency = 1 --// You can see here where the collider is positioned
		end	
	end
end

If something goes wrong, please respond so I can be aware.