function module:ApplyRagdoll(character: Model, duration: number)
duration = duration or 3.5
if character:GetAttribute("Blocking") == true then return end
local humanoid = character:FindFirstChild("Humanoid")
if humanoid:GetState() == Enum.HumanoidStateType.Dead then return end
local hrp = character:FindFirstChild("HumanoidRootPart")
if not humanoid or not hrp then return end
humanoid.AutoRotate = false
humanoid.BreakJointsOnDeath = false
humanoid.RequiresNeck = false
local offsets = {
Head = {
CFrame = {CFrame.new(0, 1, 0, 0, -1, 0, 1, 0, -0, 0, 0, 1), CFrame.new(0, -0.5, 0, 0, -1, 0, 1, 0, -0, 0, 0, 1)}
},
HumanoidRootPart = {
CFrame = {CFrame.new(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), CFrame.new(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)}
},
["Right Arm"] = {
CFrame = {CFrame.new(1.3, 0.75, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1), CFrame.new(-0.2, 0.75, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1)}
},
["Left Arm"] = {
CFrame = {CFrame.new(-1.3, 0.75, 0, -1, 0, 0, 0, -1, 0, 0, 0, 1), CFrame.new(0.2, 0.75, 0, -1, 0, 0, 0, -1, 0, 0, 0, 1)}
},
["Right Leg"] = {
CFrame = {CFrame.new(0.5, -1, 0, 0, 1, -0, -1, 0, 0, 0, 0, 1), CFrame.new(0, 1, 0, 0, 1, -0, -1, 0, 0, 0, 0, 1)}
},
["Left Leg"] = {
CFrame = {CFrame.new(-0.5, -1, 0, 0, 1, -0, -1, 0, 0, 0, 0, 1), CFrame.new(0, 1, 0, 0, 1, -0, -1, 0, 0, 0, 0, 1)}
}
}
local function buildCollisionParts()
for _, v in character:GetChildren() do
if v:IsA("BasePart") and v ~= hrp then
local p = v:Clone()
p.Parent = v
p.CanCollide = false
p.Massless = true
p.Size = Vector3.one
p.Name = "Collide"
p.Transparency = 1
p:ClearAllChildren()
local weld = Instance.new("Weld")
weld.Parent = p
weld.Part0 = v
weld.Part1 = p
end
end
end
buildCollisionParts()
local function enableMotor6D(enabled: boolean)
for _, v in character:GetDescendants() do
if v.Name == "Handle" or v.Name == "RootJoint" or v.Name == "Neck" then continue end
if v:IsA("Motor6D") then v.Enabled = enabled end
end
end
local function buildJoints()
for _, v in character:GetDescendants() do
if not v:IsA("BasePart") or v:FindFirstAncestorOfClass("Accessory") or v.Name == "Handle" or v.Name == "Torso" or v == hrp or not offsets[v.Name] then continue end
local a0: Attachment, a1: Attachment = Instance.new("Attachment"), Instance.new("Attachment")
local joint: Constraint = Instance.new("BallSocketConstraint")
a0.Name = "RAGDOLL_ATTACHMENT"
a0.Parent = v
a0.CFrame = offsets[v.Name].CFrame[2]
a1.Name = "RAGDOLL_ATTACHMENT"
a1.Parent = hrp
a1.CFrame = offsets[v.Name].CFrame[1]
joint.Name = "RAGDOLL_CONSTRAINT"
joint.Parent = v
joint.Attachment0 = a0
joint.Attachment1 = a1
v.Massless = true
end
end
local function enableCollisionParts(enabled: boolean)
for _, v in character:GetChildren() do
if v:IsA("BasePart") and v ~= hrp then
v.CanCollide = not enabled
v.Collide.CanCollide = enabled
end
end
end
local function destroyJoints()
for _, v in character:GetDescendants() do
if v.Name == "RAGDOLL_ATTACHMENT" or v.Name == "RAGDOLL_CONSTRAINT" then v:Destroy() end
if not v:IsA("BasePart") or v:FindFirstAncestorOfClass("Accessory") or v.Name == "Torso" or v.Name == "Head" then continue end
end
end
local function fling()
local force = Instance.new("LinearVelocity")
force.RelativeTo = "World"
force.MaxForce = 9999
force.Attachment0 = hrp.RootAttachment
force.VectorVelocity = hrp.CFrame.LookVector + Vector3.new(math.random(-15, 15), 35, math.random(-30, 30))
force.Parent = hrp
game.Debris:AddItem(force, 0.1)
humanoid.PlatformStand = true
end
fling()
enableMotor6D(false)
buildJoints()
enableCollisionParts(true)
task.delay(duration, function()
if not humanoid then return end
if humanoid:GetState() == Enum.HumanoidStateType.Dead then return end
humanoid.AutoRotate = true
humanoid.PlatformStand = false
humanoid.BreakJointsOnDeath = true
humanoid.RequiresNeck = true
enableMotor6D(true)
enableCollisionParts(false)
end)
end
The player gets up, but he’s still stuck. Any ideas why this happens?