How do i fix the ragdoll causing me to backflip when unragdolling

Whenever i unragdoll it sometimes causes me to do flips before standing up again, this happens to npcs and players too

Watch Roblox-2025-09-17T12_57_03.530Z | Streamable (check near the end)

local CollectionService = game:GetService("CollectionService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local ServerStorage = game:GetService("ServerStorage")

local ServerModules = ServerStorage.Modules
local ServerAssets = ServerStorage.Assets

local RagdollAssets = ServerAssets.Ragdoll

local Modules = ReplicatedStorage.Modules

local Utils = Modules.Utils

local TagUtils = require(Utils.Tag)

local PlayerStateManager = require(ServerModules.StateManager)
local AnimationHandler = require(ServerModules.AnimationHandler)

local RAGDOLL_TAG = "RagdollParts_%d"

local Garbage = workspace.Terrain:FindFirstChild("Garbage")

local RagdollHandler = {}

local function CreateColliders(Player: Player, Character: Model)
	for _, Part in ipairs(Character:GetChildren()) do
		if Part:IsA("BasePart") and Part.Name ~= "HumanoidRootPart" and Part.Name ~= "Torso" then
			local ColliderPart = Instance.new("Part")
			local WeldConstraint = Instance.new("WeldConstraint")

			ColliderPart.Size = Part.Size
			ColliderPart.CFrame = Part.CFrame
			ColliderPart.Massless = true
			ColliderPart.Transparency = 1
			ColliderPart.CollisionGroup = "RagdollColliders"
			ColliderPart.Name = "ColliderPart"

			ColliderPart:AddTag(RAGDOLL_TAG:format(Player.UserId))

			WeldConstraint.Part1 = Part
			WeldConstraint.Part0 = ColliderPart

			WeldConstraint.Parent = ColliderPart
			ColliderPart.Parent = Garbage
		end
	end
end

function RagdollHandler.Ragdoll(Player: Player)
	local Character = Player.Character

	if not Character then
		return
	end

	if not PlayerStateManager:GetState(Player, "Ragdolled") then
		PlayerStateManager:EnterState(Player, "Ragdolled")
	else
		return
	end

	local Humanoid = Character:FindFirstChildOfClass("Humanoid") :: Humanoid

	local Animator = Humanoid.Animator :: Animator
	local RootPart = Humanoid.RootPart

	coroutine.wrap(function()
		Humanoid.AutoRotate = false
		Humanoid.PlatformStand = true

		Humanoid:SetStateEnabled(Enum.HumanoidStateType.Ragdoll, false)
		Humanoid:SetStateEnabled(Enum.HumanoidStateType.FallingDown, false)
		Humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, false)
		Humanoid:SetStateEnabled(Enum.HumanoidStateType.Physics, true)
		Humanoid:ChangeState(Enum.HumanoidStateType.Physics)

		AnimationHandler:StopAllAnimations(Animator, { 2, 5 })
		RootPart.Massless = true

		CreateColliders(Player, Character)

		for _, BasePart: BasePart in ipairs(Character:GetChildren()) do
			if BasePart:IsA("BasePart") then
				for _, Motor6D in ipairs(BasePart:GetChildren()) do
					if Motor6D:IsA("Motor6D") then
						local ConnectedPart = Motor6D.Part1
						local RagdollParts = RagdollAssets:FindFirstChild(ConnectedPart.Name)

						if not RagdollParts then
							continue
						end

						local Attachment0 = RagdollParts.Attachment0:Clone()
						local Attachment1 = RagdollParts.Attachment1:Clone()

						Attachment0.Name = "RagdollAttachment"
						Attachment1.Name = "RagdollAttachment"

						local Constraint = RagdollParts.BallSocketConstraint:Clone()
						Constraint.Name = "RagdollConstraint"

						Constraint.Attachment0 = Attachment0
						Constraint.Attachment1 = Attachment1

						TagUtils:AddTags({ Attachment0, Attachment1, Constraint }, RAGDOLL_TAG:format(Player.UserId))

						Attachment0.Parent = Motor6D.Part0
						Attachment1.Parent = Motor6D.Part1

						Constraint.Parent = BasePart

						Motor6D.Enabled = false
					end
				end
			end
		end
	end)()
end

function RagdollHandler.UnRagdoll(Player: Player)
	local Character = Player.Character

	if not Character or Character and not PlayerStateManager:GetState(Player, "Ragdolled") then
		return
	end

	local Humanoid = Character:FindFirstChildOfClass("Humanoid") :: Humanoid
	local RootPart = Humanoid.RootPart

	coroutine.wrap(function()
		if Humanoid.Health > 0 then
			for _, Part in ipairs(CollectionService:GetTagged(RAGDOLL_TAG:format(Player.UserId))) do
				Part:Destroy()
			end

			RunService.Heartbeat:Wait()
			RunService.Heartbeat:Wait()

			for _, BasePart: BasePart in ipairs(Character:GetChildren()) do
				if BasePart:IsA("BasePart") then
					BasePart.AssemblyLinearVelocity = Vector3.new()
					BasePart.AssemblyAngularVelocity = Vector3.new()

					for _, Motor6D in ipairs(BasePart:GetChildren()) do
						if Motor6D:IsA("Motor6D") then
							Motor6D.Enabled = true
						end
					end
				end
			end
		end

		PlayerStateManager:TemporaryState(Player, "Stun Immunity", 0.5)

		Humanoid:SetStateEnabled(Enum.HumanoidStateType.Ragdoll, false)
		Humanoid:SetStateEnabled(Enum.HumanoidStateType.FallingDown, false)
		Humanoid:SetStateEnabled(Enum.HumanoidStateType.Physics, false)
		Humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, true)
		Humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)

		Humanoid.PlatformStand = false
		Humanoid.AutoRotate = true

		if PlayerStateManager:GetState(Player, "Ragdolled") then
			PlayerStateManager:LeaveState(Player, "Ragdolled")
		end

		RootPart.Massless = false
	end)()
end

return RagdollHandler

Does anyone know how to fix this?

it doesnt always happen but its frequent can someone help

i have a ragdoll system i made a couple months ago and what i did is i put my platform standing inside the input detection and ran it after the ragdoll code

uis.InputBegan:Connect(function(inp)
	if inp.KeyCode == Enum.KeyCode.R then
		isRagdoll.Value = not isRagdoll.Value -- toggle ragdoll state
		
		if isRagdoll.Value == true then -- if ragdolling then fire the ragdoll event and force into plat stand
			ragdollEvent:FireServer(false, false)
			hum.PlatformStand = true
			hum:ChangeState(Enum.HumanoidStateType.PlatformStanding)
		else -- if getting up then fire the ragdoll event and force out of plat stand
			ragdollEvent:FireServer(true, false)
			hum.PlatformStand = false
			hum:ChangeState(Enum.HumanoidStateType.GettingUp)
		end
	end
end)

-- the 2 values in ragdollEvent are just "GettingUp" and "IsDead".
-- just small checks you dont need to worry about
1 Like

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