Troubles With Ragdoll (Works With Weird Parenting)

Hey!
I am using a ragdoll system Weldify provided in the post Temporary Ragdoll?

However,

While modifying this system to be formatted in a way I prefer and work within my game, I realized that it only works with a regular script parented to the character model, however with the same exact system in place parented elsewhere, it kills the player…?

Behavior When Ran Inside Of Character Model
image
RobloxRagdoll_InCharacter

Behavior When Ran Inside Of ServerScriptService
image
RobloxRagdoll_InServer

Code Within The Script
--//Services\\--
local RepStorage = game:GetService("ReplicatedStorage")

--//Connections\\--
local Connections = RepStorage.Connections
local Ragdoll = Connections.Ragdoll

--//Variables\\--
local Ragdolls = {}

--//Logic\\--
Ragdoll.OnServerEvent:Connect(function(Player, Ragdolled)
	local Character = Player.Character or Player.CharacterAdded:Wait()
	if Ragdolled then
		Ragdolls[Player] = Player
		
		for _, Motor in pairs(Character:GetDescendants()) do
			if Motor:IsA("Motor6D") then
				if Motor.Name ~= "Root" and Motor.Name ~= "RootJoint" then
					local Att0 = Instance.new("Attachment")
					Att0.Name = "RagdollSocket"
					Att0.CFrame = Motor.C0
					Att0.Parent = Motor.Part0
					local Att1 = Instance.new("Attachment")
					Att1.Name = "RagdollSocket"
					Att1.CFrame = Motor.C1
					Att1.Parent = Motor.Part1

					local Socket = script.RagdollJoints:FindFirstChild(Motor.Name)
					Socket.Attachment0 = Att0
					Socket.Attachment1 = Att1
					Socket.Enabled = true

					Motor.Enabled = false
				end
			end
		end

		Character.HumanoidRootPart.CanCollide = false
		Character.HumanoidRootPart.Massless = true
		
	else
		Ragdolls[Player] = nil
		
		local Sockets = {}
		for _, v in pairs(Character:GetDescendants()) do
			if v:IsA("Motor6D") then
				v.Enabled = true
			elseif v.Name == "RagdollSocket" then 
				table.insert(Sockets,v)
			elseif v.Parent.Name == "RagdollJoints" then
				v.Enabled = false
			end
		end
		for _, v in pairs(Sockets) do v:Destroy() end

		Character.HumanoidRootPart.CanCollide = true
		Character.HumanoidRootPart.Massless = false
	end
end)

Very confused by this odd behavior as it’s the exact same code, just in a different place
I was wondering if anyone would be able to help me figure this out!

1 Like

I figured it out…

It turns out due to the script fetching the Ragdoll Joints within the script (When In ServerScriptService), they didn’t exist within workspace… a slight oversight on my part.

I moved the script to ServerScriptService and kept the joints within my character and that made everything work as intended.

Thank you to anyone who checked this out and I apologize for wasting your time if you spent time trying to figure this out lol.