[PARTIALLY SOLVED] Ragdoll mechanic leaves the character dangling on it's RootPart (R15)

Deleting the RootPart results in the camera going unconventional ways (which definitely just means I shouldn’t have deleted it), and somehow I can still move the character. (And for ‘I don’t know’ reasons.)

Here’s my script by the way, it’s nothing special. It might look spaghetti-like because I’m using strict coding.

--!native
--!optimize 2
--!strict

local Character: Model = script.Parent
local Player: Player = game.Players:GetPlayerFromCharacter(Character)
local Humanoid: Humanoid? = Character:FindFirstChildOfClass('Humanoid')
local RootPart: BasePart? = nil

local RagdollVal: BoolValue = Instance.new('BoolValue')
RagdollVal.Name = 'Ragdoll'
RagdollVal.Parent = Character

RagdollVal.Changed:Connect(function(value: boolean)
	if Humanoid then
		RootPart = Humanoid.RootPart
		if RootPart then
			RootPart.CanCollide = not value -- false if ragdoll
			for _, v in Character:GetDescendants() do
				if v:IsA('BasePart') and v.Name == 'Head' then
					v.CanCollide = value -- true if ragdoll
				end
				if v:IsA('Motor6D') then
					if value then
						local Att0: Attachment, Att1: Attachment = Instance.new('Attachment'), Instance.new('Attachment')
						Att0.CFrame = v.C0
						Att1.CFrame = v.C1
						Att0.Parent = v.Part0
						Att1.Parent = v.Part1
						local BSC: BallSocketConstraint = Instance.new('BallSocketConstraint')
						BSC.Attachment0 = Att0
						BSC.Attachment1 = Att1
						BSC.Parent = v.Part0
						if v.Part1 and v.Part1.Name ==  'Head' then
							BSC.LimitsEnabled = true
							BSC.TwistLimitsEnabled = true
						end
					else
						local Att0: Attachment?, Att1: Attachment? = nil, nil
						local BSC: BallSocketConstraint? = nil
						if v.Part0 then
							Att0 = v.Part0:FindFirstChildWhichIsA('Attachment')
							BSC = v.Part0:FindFirstChildWhichIsA('BallSocketConstraint')
						end
						if v.Part1 then
							Att1 = v.Part1:FindFirstChildWhichIsA('Attachment')
						end
						
						if Att0 then
							Att0:Destroy()
						end
						if Att1 then
							Att1:Destroy()
						end
						if BSC then
							BSC:Destroy()
						end
					end
					v.Enabled = not value -- false if ragdoll
				end
				if v:IsA('Weld') and v.Name == 'AccessoryWeld' then
					if value then
						local WC: WeldConstraint = Instance.new('WeldConstraint')
						WC.Part0 = v.Part0
						WC.Part1 = v.Part1
						WC.Parent = v.Parent
					else
						local WC: WeldConstraint? = nil
						if v.Parent then
							WC = v.Parent:FindFirstChildWhichIsA('WeldConstraint')
						end
						if WC then
							WC:Destroy()
						end
					end
					v.Enabled = not value -- false if ragdoll
				end
			end
		end
	end
end)

Also, I would like to mention that any tips to improving my spaghetti code is appreciated, but you don’t have to, of course.

1 Like

Try making the RootPart’s cancollide to false

HumanoidRootPart.Cancollide = false
1 Like

The RootPart’s collision is already off, though. :thinking:

Thats weird
Is it a localscript in startercharservice? (where is it located) I want to test it out

It’s a normal serverscript, and yes, in starterchar.

Its not ragdolling for me? I pressed respawn and it just does the normal r15 death, should i switch my avatar to r6?
I tried r6 and it doesnt work

its a ragdolling and unragdolling script btw (sorry i forgot to tell you xd), you have to enable and disable the ragdoll value through the server

Ohhhhh

If its r15 try setting the lower / upper torso’s cancollide to false

I (kind of) found the solution? But I also didn’t?
Setting the PlatformStand to true makes it work, but here’s the thing, it’s not ragdolling properly like a normal ragdoll would. (Only the torso is collidable)
To simulate the same effect as the ragdoll on death (this script is modified from a ragdoll on death script, which would’ve worked flawlessly and perfectly), all the BaseParts are collidable. Enabling the ragdoll value happens to make it become possessed in… unconventional and unintentional ways. (aka it just flings itself, detaches and reattaches it’s own limbs.)
Honestly, I’ve got no idea how to deal with this, but I’ll mark this as solved until I find another solution.

When a character is added, you need to create small Vector3.one sized collison parts at the positions of each limb and weld them to each limb of the character. Then simply enable the collision of these parts when the player is ragdolled. If you would like, i can provide you with a module that does this.

1 Like


you will get ragdolls that look like this

Kind of smart, actually. I’ll try these soon.
Update: It kind of works, but with R15 characters with varying proportions, it would break some characters. However in R6, everything would work flawlessly with the script, even without the collision parts involved. Therefore, the ragdoll script sadly only works with R6 and not R15.

You could try smaller parts, and remove the collisions for the hands and feet.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.