How to make ragdoll

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to make ragdoll when got hit or punched
  2. What is the issue? Include screenshots / videos if possible!
    Here is a video, that shows how I want:

Here is script for tool:

local punch = script.Parent
local remote = punch.Remote
local hitpart = punch.HitPart
local humanoidlist = {}
local touch
local debris = game:GetService("Debris")
local char
local hrp

function CheckHumanoid(hum)
	for i, v in pairs(humanoidlist) do
		if humanoidlist[i] == hum then
			return true
		end
	end
	return false
end

function Velocity(x, y, z, maxtorque, maxforce, vector, hit)
	local attachment = Instance.new("Attachment", hit)
	local linear = Instance.new("LinearVelocity", hit)
	linear.MaxForce = maxforce
	linear.Attachment0 = attachment
	linear.RelativeTo = Enum.ActuatorRelativeTo.World
	linear.VectorVelocity = vector

	local angular = Instance.new("AngularVelocity", hit)
	angular.MaxTorque = maxtorque
	angular.AngularVelocity = Vector3.new(x, y, z)
	angular.Attachment0 = attachment
	angular.RelativeTo = Enum.ActuatorRelativeTo.Attachment0

	debris:AddItem(angular, 0.5)
	debris:AddItem(linear, 0.5)
	debris:AddItem(attachment, 0.5)
end

local function initialize()
	punch.Enabled = true
	char = punch.Parent
	hrp = char:FindFirstChild("HumanoidRootPart")

	local weld = hitpart:FindFirstChild("Weld")
	if weld then
		weld.Part0 = char:FindFirstChild("Right Arm")
		weld.Part1 = hitpart
	end

	local humanoid = char:FindFirstChildOfClass("Humanoid")
	if humanoid then
		humanoid.Died:Connect(function()
			punch.Enabled = false
			if touch then
				touch:Disconnect()
				touch = nil
			end
		end)
	end
end

function cooldown()
	coroutine.wrap(function()
		punch.Enabled = false
		local cooldownTime = 10 -- Установка времени отката на 10 секунд
		local interval = 0.1
		local steps = cooldownTime / interval

		for i = 1, steps do
			punch.Name = "[" .. string.format("%.1f", cooldownTime - (i * interval)) .. "]"
			wait(interval)
		end

		punch.Name = "Haymaker"
		punch.Enabled = true
	end)()
end

function ApplyRagdoll(character)
	local humanoid = character:FindFirstChildOfClass("Humanoid")
	if humanoid and humanoid.Health > 0 then
		humanoid:ChangeState(Enum.HumanoidStateType.Physics)
	end

	for _, part in pairs(character:GetChildren()) do
		if part:IsA("BasePart") and part ~= hrp then
			part:SetNetworkOwner(nil)
			if part:FindFirstChildOfClass("Motor6D") then
				local constraint = Instance.new("BallSocketConstraint")
				constraint.Parent = part
				constraint.Attachment0 = Instance.new("Attachment", part)
				constraint.Attachment1 = Instance.new("Attachment", part.Parent:FindFirstChild(part.Name))
				debris:AddItem(constraint, 2)
			end
		end
	end

	wait(2)

	if humanoid and humanoid.Health > 0 then
		humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
	end

	for _, part in pairs(character:GetChildren()) do
		if part:IsA("BasePart") and part ~= hrp then
			part:SetNetworkOwner(game.Players:GetPlayerFromCharacter(character))
		end
	end
end

remote.OnServerInvoke = function(plr, action)
	if action == "Swing" then
		if punch.Enabled == true then
			punch.Enabled = false

			delay(0.2, function()
				touch = hitpart.Touched:Connect(function(hit)
					if hit and hit.Parent then
						local hum = hit.Parent:FindFirstChildOfClass("Humanoid")
						if hum then
							local check = CheckHumanoid(hum)
							local otherhrp = hit.Parent:FindFirstChild("HumanoidRootPart")
							if otherhrp and hrp then
								local delta = otherhrp.Position - hrp.Position
								if not check then
									table.insert(humanoidlist, hum)
									Velocity(0, 0, 25, 40, 9999999, delta * 20, otherhrp)  -- Увеличен импульс
									hum:TakeDamage(10)
									hitpart.Hit:Play()
									ApplyRagdoll(hit.Parent)

									-- Add creator tag
									local creatorTag = Instance.new("ObjectValue")
									creatorTag.Name = "creator"
									creatorTag.Value = plr
									creatorTag.Parent = hum
									debris:AddItem(creatorTag, 2)  -- Adjust duration as needed

									wait(1)
									humanoidlist = {}
								end
							end
						end
					end
				end)
			end)

			delay(1, function()
				if touch then
					touch:Disconnect()
					touch = nil
				end
			end)

			cooldown()
			return true
		end
	end
end

punch.Equipped:Connect(initialize)

punch.SwingSound.OnServerEvent:Connect(function(plr)
	hitpart.Swing:Play()
end)

Also I can add you on studio and you can check. Please help me!

1 Like

Found this topic, there’s a model uploaded there you can use

You could also just see the humanoid state to ragdoll and apply some body movers to but I don’t know what effects you desire so try both

1 Like

Ragdoll is working, but I need when player got hit or punched( punched by a tool meaning), here is video
robloxapp-20250102-1349506.wmv (6.1 MB)

Nevermind, I did another script and worked. Thank you!

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