How do i use ragdoll?

I want to make it so the player can ragdoll others when they get hit by their move, but i have no idea how it would be made, this is my script so far i want to add the ragdoll code inside the ragdollcharacter function

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local slapEvent = ReplicatedStorage:FindFirstChild("RemoteEvents"):FindFirstChild("WhackEvent") 


local SLAP_DAMAGE = 20 


local function ragdollCharacter(character)

end

slapEvent.OnServerEvent:Connect(function(player)
	local char = player.Character
	if not char or not char:FindFirstChild("HumanoidRootPart") then return end
	local root = char.HumanoidRootPart

	-- Play slap sound
	local slapSound = Instance.new("Sound")
	slapSound.SoundId = "rbxassetid://13114759"
	slapSound.Volume = 2
	slapSound.Parent = root
	slapSound:Play()
	game:GetService("Debris"):AddItem(slapSound, 3)

	-- Slap hitbox check
	local region = Region3.new(root.Position - Vector3.new(3,3,3), root.Position + Vector3.new(3,3,3))
	local parts = workspace:FindPartsInRegion3(region, char, math.huge)

	for _, part in ipairs(parts) do
		local otherChar = part:FindFirstAncestorOfClass("Model")
		local otherHumanoid = otherChar and otherChar:FindFirstChildOfClass("Humanoid")
		if otherChar and otherChar ~= char and otherHumanoid and otherHumanoid.Health > 0 then
			-- Apply damage
			otherHumanoid:TakeDamage(SLAP_DAMAGE)

			-- Ragdoll effect
			ragdollCharacter(otherChar)
			break
		end
	end
end)

Ragdolling is a pretty in-depth thing, I would advise creating a module (OOP preferably) for this instead of trying to shove it into a function.

Beyond that it’d be unproductive to give you code to copy paste because nobody can make a script for you. That’s on you to do. Nobody can exactly predict what you want to the tea.

Try making it yourself, look up resources and helpful guides, beyond that there’s not much anyone else can do to help you.

1 Like

Ragdolling is based on BallSocketConstraint and humanoid state managment. I have a script for you.

local Ragdoll = {}

-- Start ragdoll
function Ragdoll.start(character: Model)
	local humanoid = character:FindFirstChildWhichIsA("Humanoid")
	
	if humanoid:HasTag("Ragdoll") then
		return
	end
	
	humanoid:AddTag("Ragdoll")
	for i, joint in pairs(character:GetDescendants()) do
		if joint:IsA('Motor6D') then
			local socket = Instance.new('BallSocketConstraint')
			local a0 = Instance.new('Attachment')
			local a1 = Instance.new('Attachment')
			a0.Parent = joint.Part0
			a1.Parent = joint.Part1
			socket.Parent = joint.Parent
			socket.Attachment0 = a0
			socket.Attachment1 = a1
			a0.CFrame = joint.C0
			a1.CFrame = joint.C1
			socket.LimitsEnabled = true
			socket.TwistLimitsEnabled = true
			joint.Enabled = false
		end
	end
	
	local humanoid = character:FindFirstChild('Humanoid')
	humanoid:ChangeState(Enum.HumanoidStateType.Ragdoll, true)
	
	character.Humanoid.WalkSpeed = 0
	character.Humanoid.JumpPower = 0
	character.Humanoid.PlatformStand = true
	character.Humanoid.AutoRotate = false
end

-- Stop rgadoll
function Ragdoll.stop(character: Model)
	local humanoid = character:FindFirstChildWhichIsA('Humanoid')

	humanoid.PlatformStand = false

	for i, joint in pairs(character:GetDescendants()) do
		if joint:IsA('BallSocketConstraint') then
			joint:Destroy()
		end
		if joint:IsA('Motor6D') then
			joint.Enabled = true
		end
	end

	humanoid:RemoveTag("Ragdoll")
	
	humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
	humanoid.WalkSpeed = 16
	humanoid.JumpPower = 50
	humanoid.AutoRotate = true
end

return Ragdoll

Make sure to run it on server.

2 Likes

You can make a simple ragdoll effect by disabling the humanoids PlatformStand and applying Motor6D breakage so the limbs move freely.



local function ragdollCharacter(character)
    local humanoid = character:FindFirstChildOfClass("Humanoid")
    if not humanoid then return end

    -- rnable rdoll
    humanoid.PlatformStand = true

    -- break Motor6Ds to let limbs flop arround lol
    for _, joint in ipairs(character:GetDescendants()) do
        if joint:IsA("Motor6D") then
            joint:Destroy()
        end
    end

    -- re-enable after a delay (dont know if you want this thoe)
    task.delay(3, function()
        if humanoid and humanoid.Parent then
            humanoid.PlatformStand = false
            -- you would need to rebuild joints if you want to fully restore movement thingi
        end
    end)
end

This makes the character collapse and flop when hit. Its basic but works for hits like your slap move. You could also add velocity to limbs for more effect or use constraints to make it more realistic! Just remember that re-creating the original joints is required if you want the player to get back up normally… (i dont think i need to tell you this but ill do it anyway)

With this whenever your slapEvent hits another character the ragdollCharacter function will handle the ragdoll effect automatically.

Hope this helped you!!!

1 Like