Smooth ragdoll system

today im releasing a ragdoll module i created out of spite due to there being no real good solution for ragdolls (atleast ones that i could find and liked)
Now, there is one requirement to using this ragdoll module which is you need to have the Avatar joint update enabled in your place. (devforum post link to learn more about it)

here is the showcase of the ragdoll itself now :

MODULE SOURCE CODE :

--!strict
local Ragdoll = {}

-- // SERVICES \\ --
local RunService = game:GetService("RunService")
local PhysicsService = game:GetService("PhysicsService")

function Ragdoll.SetupClient(Character : Model)
	if not RunService:IsClient() then
		return
	end
	
	local Humanoid = Character:WaitForChild("Humanoid") :: Humanoid

	Humanoid:SetStateEnabled(Enum.HumanoidStateType.FallingDown, false)
	Humanoid:SetStateEnabled(Enum.HumanoidStateType.Ragdoll, false)

	Character:WaitForChild("HumanoidRootPart")

	local function Apply()
		Ragdoll.Ragdoll(Character, Character:GetAttribute("Ragdolled") == true)
	end

	Character:GetAttributeChangedSignal("Ragdolled"):Connect(Apply)

	if Character:GetAttribute("Ragdolled") == true then
		Apply()
	end
end

function Ragdoll.SetupServer(Character : Model) : (boolean, string?)
	if not RunService:IsServer() then
		return false, "Don't run this on the client"
	end
	
	local Humanoid = Character:FindFirstChild("Humanoid") :: Humanoid
	
	if not Humanoid or not Humanoid:IsA("Humanoid") then
		return false, "No humanoid found"
	end
	
	local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart") :: BasePart
	
	if not HumanoidRootPart or not HumanoidRootPart:IsA("BasePart") then
		return false, "No HumanoidRootPart found"
	end
	
	PhysicsService:RegisterCollisionGroup("Players")
	PhysicsService:CollisionGroupSetCollidable("Players", "Players", false)
	
	Humanoid.BreakJointsOnDeath = false
	
	for _, Part in Character:GetDescendants() do
		if not Part:IsA("BasePart") then
			continue
		end
		
		Part.CollisionGroup = "Players"
		
	end
	
	if not HumanoidRootPart:FindFirstChild("RootWeld") then
		local RootWeld = Instance.new("WeldConstraint")
		RootWeld.Name = "RootWeld"

		RootWeld.Part0 = HumanoidRootPart
		RootWeld.Part1 = Character:FindFirstChild("LowerTorso") :: BasePart

		RootWeld.Enabled = false
		RootWeld.Parent = HumanoidRootPart
	end
	
	return true, nil
end

function Ragdoll.Ragdoll(Character : Model, Ragdolled : boolean) : (boolean, string?)
	local Humanoid = Character:FindFirstChild("Humanoid") :: Humanoid

	if not Humanoid or not Humanoid:IsA("Humanoid") then
		return false, "No humanoid found"
	end
	
	local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart") :: BasePart

	if not HumanoidRootPart or not HumanoidRootPart:IsA("BasePart") then
		return false, "No HumanoidRootPart found"
	end
	
	Character:SetAttribute("Ragdolled", Ragdolled)
	
	for _, v in Character:GetDescendants() do
		if not v:IsA("AnimationConstraint") then
			continue
		end
		
		v.Enabled = not Ragdolled
	end
	
	local rootWeld = HumanoidRootPart:FindFirstChild("RootWeld") :: WeldConstraint
	if rootWeld then
		rootWeld.Enabled = Ragdolled
	end
	
	(Character:FindFirstChild("Head") :: BasePart).CanCollide = Ragdolled
	HumanoidRootPart.CanCollide = not Ragdolled
	Humanoid.AutoRotate = not Ragdolled
	Humanoid:ChangeState(Enum.HumanoidStateType[Ragdolled and "Physics" or "GettingUp"])
	
	return true, nil
end

return Ragdoll

ragdoll test | Play on Roblox example place
if you have any questions or suggestions on how to improve the module and make it smoother PLEASE reply to the post because i want to keep on improving this

1 Like

Wth why are y’all hiring vegeta?

is this ragdoll module endorsed by the prince of all saiyans, vegeta?