Ragdoll System like Strongest Battleground

I tried to make a Ragdoll System that is similar to the Ragdoll System as in Strongest Battleground.
You only need 1 script for this.

Test Place

RagdollSystem.rbxl (62.0 KB)

Script:

local Players = game:GetService("Players")
local ps = game:GetService("PhysicsService")

ps:RegisterCollisionGroup("NonPlayers")
ps:RegisterCollisionGroup("Players")

ps:CollisionGroupSetCollidable("NonPlayers", "Players", false)
ps:CollisionGroupSetCollidable("NonPlayers", "NonPlayers", false)

local function CreateJoint(j_type, p0, p1, c0, c1)
	local nj = Instance.new(j_type)
	nj.Part0 = p0 nj.part1 = p1
	if c0 ~= nil then nj.C0 = c0 end
	if c1 ~= nil then nj.C1 = c1 end
	nj.Parent = p0
end

local function setNetworkNil(char)
	for i,v in pairs(char:GetChildren()) do
		if v:IsA("BasePart") then
			v:SetNetworkOwner(nil)
		end
	end
end

local AttactmentData = { --Limb socket attaching to Torso
	--["AttachmentTag"] = {part_name, part_attachment, torso_attachment, relative_position}
	["RA"] = {"Right Arm", CFrame.new(0, 0.5, 0), CFrame.new(1.5, 0.5, 0), CFrame.new(1.5, 0, 0)},
	["LA"] = {"Left Arm", CFrame.new(0, 0.5, 0), CFrame.new(-1.5, 0.5, 0), CFrame.new(-1.5, 0, 0)},
	["RL"] = {"Right Leg", CFrame.new(0, 0.5, 0), CFrame.new(0.5, -1.5, 0), CFrame.new(0.5, -2, 0)},
	["LL"] = {"Left Leg", CFrame.new(0, 0.5, 0), CFrame.new(-0.5, -1.5, 0), CFrame.new(-0.5, -2, 0)},
}

local function SetupRagdoll(char)
	
	local collision_part = Instance.new("Part")
	collision_part.Name = "CP"
	collision_part.TopSurface = Enum.SurfaceType.Smooth
	collision_part.BottomSurface = Enum.SurfaceType.Smooth
	collision_part.Size = Vector3.new(1, 0.25, 1)
	collision_part.Transparency = 1
	collision_part.CanCollide = false
	
	local collision_parts = Instance.new("Model", char)
	collision_parts.Name = "CollisionParts"
	
	char:FindFirstChild("Humanoid").BreakJointsOnDeath = false
	char:FindFirstChild("Humanoid").RequiresNeck = false
	
	local hdv = char:FindFirstChild("Head")

	local f_head

	local fhum = char:FindFirstChild("Humanoid")

	local Torso = char:FindFirstChild("Torso")

	if Torso then
		for att_tag, att_data in pairs(AttactmentData) do
			local get_limb = char:FindFirstChild(att_data[1])
			if get_limb ~= nil then

				local att1 = Instance.new("Attachment")
				att1.Name = att_tag
				att1.CFrame = att_data[2]
				att1.Parent = get_limb

				local att2 = Instance.new("Attachment")
				att2.Name = att_tag
				att2.CFrame = att_data[3]
				att2.Parent = Torso

				local socket = Instance.new("BallSocketConstraint")
				socket.Name = att_tag .. "_SOCKET"
				socket.Attachment0 = att2
				socket.Attachment1 = att1
				socket.LimitsEnabled = true
				socket.TwistLimitsEnabled = true
				socket.Radius = 5
				socket.Parent = Torso

				task.delay(1, function()
					local cp = collision_part:Clone()
					local cp_weld = Instance.new("Weld")
					cp_weld.C0 = CFrame.new(0, -0.85, 0)
					cp_weld.Part0 = get_limb
					cp_weld.Part1 = cp
					cp_weld.Parent = cp
					cp.CollisionGroup = "NonPlayers"
					cp.Name = "Hitbox_"..tostring(get_limb)
					cp.Parent = char
				end)

				fhum:GetAttributeChangedSignal("Ragdolled"):Connect(function(property)
					local isRagdolled = fhum:GetAttribute("Ragdolled")
					for _, collision in pairs(collision_parts:GetDescendants()) do
						if collision:IsA("BasePart") then
							collision.CanCollide = isRagdolled
						end
					end
				end)

			end
		end
	end
	
end

local function Ragdoll(char)
	local Head = char:FindFirstChild("Head")
	local Torso = char:FindFirstChild("Torso")
	
	local Humanoid = char:FindFirstChildOfClass("Humanoid")
	Humanoid.AutoRotate = false
	
	local collision_parts = char:FindFirstChild("CollisionParts")
	local isRagdolled = char:FindFirstChild("Humanoid"):GetAttribute("Ragdolled")
	isRagdolled = true
	
	for _, part in pairs(collision_parts:GetDescendants()) do
		if part:IsA("BasePart") and not part:IsDescendantOf(collision_parts) then
			part.CollisionGroup = "Players"
		end
	end

	if Torso then
		Torso.Velocity = Vector3.new(math.random(), 1, math.random()).unit * 9 + (Vector3.new(0, 0.15, 0))
		for _, motor6D in pairs(Torso:GetDescendants()) do
			if motor6D:IsA("Motor6D") and motor6D.Part0 == Torso then
				motor6D:Destroy()
			end
		end
	end
	setNetworkNil(char)
	
	if Head then
--		camera.CameraSubject = Head
		CreateJoint("Weld", Torso, Head, CFrame.new(0, 1.5, 0))
	end
end

Players.PlayerAdded:Connect(function(addedPlayer)
	
	addedPlayer.CharacterAdded:Connect(function(addedCharacter)
		
		for _, part in pairs(addedCharacter:GetDescendants()) do
			if part:IsA("BasePart") then
				part.CollisionGroup = "Players"
			end
		end
		
		local Humanoid = addedCharacter:FindFirstChildOfClass("Humanoid")
		
		SetupRagdoll(addedCharacter)
		
		Humanoid.Died:Connect(function()
			Ragdoll(addedCharacter)
		end)
		
	end)
	
end)

For test ragdoll you need reset your character.

5 Likes

I like the idea, the video does not really show the ragdoll at its finest, you could add a longer video

3 Likes

I understand, I think it’s best to let everyone test it for themselves.

would be nice to have a way to unragdoll if thats possible with this one

I don’t think it’s not hard to do it yourself. I’m too lazy to add anything to this system. This is just an example of how Ragdoll is made in strongest battleground, not a free asset from the game