So I made a ragdoll script and made a player ragdoll every time it gets hit with the last punch in the combo.
I am trying to un-ragdoll it after 3 seconds by deleting the collision parts, ball socket constrains, and welds.
I tested it, and the player can walk, but with a head looking up. All other mechanics like dash, jump, and camera are broken, and I get errors like:
HumanoidRootPart is not a valid member of Model "Workspace.Player2" - on ragdolled player
This is the part of the punch script:
if isLast then
velocity.VectorVelocity = away * 70
hit.Parent:WaitForChild("Humanoid").PlatformStand = true
local character = hit.Parent
local motorsToConvert = {}
-- Get motor6D parts and destroy the motor
for _, descendant in ipairs(character:GetDescendants()) do
if descendant:IsA("Motor6D") then
table.insert(motorsToConvert, {
name = descendant.Name,
part0 = descendant.Part0,
part1 = descendant.Part1
})
descendant.Enabled = false
end
end
-- Replace with ball socket constraints
for _, data in ipairs(motorsToConvert) do
local attachName = data.name .. "RigAttachment"
local attach0 = data.part0:FindFirstChild(attachName)
local attach1 = data.part1:FindFirstChild(attachName)
if attach0 and attach1 then
local socket = Instance.new("BallSocketConstraint")
socket.Attachment0 = attach0
socket.Attachment1 = attach1
socket.Parent = data.part0
socket.Enabled = true
else
warn("Missing attachments for: " .. data.name)
end
end
-- Add collision blocks
for _, child in ipairs(character:GetChildren()) do
if child:IsA("MeshPart") then
local block = Instance.new("Part")
block.Size = child.Size - Vector3.new(0.5, 0.5, 0.5)
block.Transparency = 1
block.CanCollide = true
block.Massless = true
block.Anchored = false
block.Parent = child
local weld = Instance.new("Weld")
weld.Part0 = block
weld.Part1 = child
weld.Parent = child
end
end
spawn(function()
task.wait(3)
for _, descendant in ipairs(character:GetDescendants()) do
if descendant:IsA("BallSocketConstraint") or descendant:IsA("Part") or descendant:IsA("Weld") then
descendant:Destroy()
end
if descendant:IsA("Motor6D") then
descendant.Enabled = true
end
end
hit.Parent:WaitForChild("Humanoid").PlatformStand = false
end)
end