Ragdoll Allows Jumping

So I’ve been working on a game for quite some while now, and my ragdoll has always had an issue where sometimes you would be able to jump while ragdolled. Back then I brushed it off as an inconsistent and not important bug.

but recently I’ve realized that this happends every single time if you are holding space right before the ragdoll, making this bug incredibly consistent an easy to pull off. And since this completely destroys the point of the ragdoll in the first place, this is now very important.

I’ve tried everything from fixing it myself, to looking it up online to even asking chatGPT, and nothing gave me working answers. So if anyone could help me that would be awesome. Thanks!

RagdollModule in ReplicatedStorage:

local RagdollModule = {}

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

pcall(function()
	PhysicsService:RegisterCollisionGroup("Ragdoll")
	PhysicsService:CollisionGroupSetCollidable("Ragdoll", "Ragdoll", false)
end)

local originalMotorData = {}

local function createSocket(part0, part1, name, c0, c1)
	local a0 = Instance.new("Attachment")
	a0.Name = name .. "_A0"
	a0.CFrame = c0 or CFrame.new(0, 0.5, 0)
	a0.Parent = part0

	local a1 = Instance.new("Attachment")
	a1.Name = name .. "_A1"
	a1.CFrame = c1 or CFrame.new(0, -0.5, 0)
	a1.Parent = part1

	local socket = Instance.new("BallSocketConstraint")
	socket.Name = name .. "_Socket"
	socket.Attachment0 = a0
	socket.Attachment1 = a1
	socket.LimitsEnabled = true
	socket.UpperAngle = 45
	socket.TwistLimitsEnabled = true
	socket.TwistLowerAngle = -30
	socket.TwistUpperAngle = 30
	socket.Parent = part0
end

function RagdollModule.RagdollCharacter(character)
	if not character or not character:IsDescendantOf(workspace) then return end

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

	local player = Players:GetPlayerFromCharacter(character)
	if not player then
		warn("Could not find player for character during ragdoll")
		return
	end

	if not originalMotorData[player.UserId] then
		originalMotorData[player.UserId] = {}
	end

	for _, track in pairs(humanoid:GetPlayingAnimationTracks()) do
		track:Stop()
	end

	humanoid:ChangeState(Enum.HumanoidStateType.Physics)
	humanoid.AutoRotate = false
	humanoid.PlatformStand = true

	for _, motor in pairs(character:GetDescendants()) do
		if motor:IsA("Motor6D") then
			local part0 = motor.Part0
			local part1 = motor.Part1
			local jointName = motor.Name

			table.insert(originalMotorData[player.UserId], {
				Name = jointName,
				Part0 = part0,
				Part1 = part1,
				C0 = motor.C0,
				C1 = motor.C1
			})

			createSocket(part0, part1, jointName, motor.C0, motor.C1)
			motor:Destroy()
		end
	end

	for _, part in pairs(character:GetDescendants()) do
		if part:IsA("BasePart") then
			part.Anchored = false
			part.CanCollide = true
			part.CollisionGroup = "Ragdoll"
			part.Velocity += Vector3.new(math.random(), math.random(), math.random()) * 0.1
		end
	end
end

function RagdollModule.UnragdollCharacter(character)
	if not character then return end

	local player = Players:GetPlayerFromCharacter(character)
	if not player then return end

	local data = originalMotorData[player.UserId]
	if not data then return end

	for _, jointData in ipairs(data) do
		local motor = Instance.new("Motor6D")
		motor.Name = jointData.Name
		motor.Part0 = jointData.Part0
		motor.Part1 = jointData.Part1
		motor.C0 = jointData.C0
		motor.C1 = jointData.C1
		motor.Parent = jointData.Part0
	end

	local humanoid = character:FindFirstChildOfClass("Humanoid")
	if humanoid then
		humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
		humanoid.AutoRotate = true
		humanoid.PlatformStand = false
	end

	originalMotorData[player.UserId] = nil
end

return RagdollModule

just disconnect player from character (althrough be careful) and also ipairs/pairs is no longer relevant in Luau

how do I disconnect the player from the character?

local char = Plr.Character
Plr.Character=nil
char.Parent=workspace

this makes my character completely disapear.

oh wait right i edited the post
It should work now

How do i unragdoll the character?

:man_shrugging:
I mean it doesnt jump…right?
If it works it works :joy::money_mouth_face::money_mouth_face::money_mouth_face:

Saying ‘ipairs/pairs is no longer relevant in Luau’ is incorrect, here’s an example where you’d want to use ipairs() to iterate only through the array portion of a table and in correct numerical order.

local t = {"apple", "banana", "mango", "strawberry", foo = "bar", abc = "def"}

for i, v in ipairs(t) do
	print(i, v) -- will print only "apple", "banana", "mango", and "strawberry"
end

Disable the Jumping state when in ragdoll, or set their JumpPower/JumpHeight to zero temporarily.

I recommend the former method.

Thanks! I’m surprised I didn’t think of this before lol

Is it useful in the example of OP?

  • NO!? THEN NO LONGER RELEVANT!

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