I have been creating a ragdoll system, using a method I found in another post Found here in which a “dummy player” of sorts is spawned in and ragdolled, leaving the actual player to be interacted with as usual.
I’ve completed the ragdoll, however I’m stumped on how they not only lock the ragdolled-dummy on the X and Z axes, but also seemingly allow it to move up and down, as well as rotate fully.
The dummy also falls over, unlike mine, but I assume finding a more “correct” way to hold the dummy in place will probably fix that secondary problem of mine.
My current code (activated from outside scripts) is this:
RagdollEvent.OnClientEvent:Connect(function(RagdollEntityName, Deleting)
if Deleting == true then
local Ragdoll = workspace:FindFirstChild("Knocked"..RagdollEntityName)
if Ragdoll ~= nil then
Ragdoll:Destroy()
end
return end
local Entity = workspace:FindFirstChild(RagdollEntityName)
for _, Object in Entity:GetDescendants() do
if Object:IsA("BasePart") then
Object.CollisionGroup = RagdollEntityName.."GhostCollision"
end
end
local RagdollEntity = Entity:Clone()
local RagdollHumanoid = RagdollEntity.Humanoid
local RagdollHRP = RagdollEntity.HumanoidRootPart
RagdollHumanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
RagdollHumanoid.HealthDisplayType = Enum.HumanoidHealthDisplayType.AlwaysOff
RagdollEntity.Name = "Knocked"..RagdollEntityName
for _, Object in pairs(RagdollEntity:GetDescendants()) do
if Object:IsA("BasePart") then
Object.CollisionGroup = RagdollEntityName.."RagdollCollision"
if Object.Name ~= "HumanoidRootPart" and Object.Name ~= "FaceHead" and Object.Name ~= "Handle" then
Object.Transparency = 0
if Object:FindFirstAncestorOfClass("Accessory") then continue end
Object.CanCollide = true
end
end
if Object.Name == "Handle" then
if Object:IsA("MeshPart") then
Object.Transparency = 0
elseif Object:IsA("Part") then
if Object:FindFirstChildOfClass("SpecialMesh") then
Object.Transparency = 0
else
Object.Transparency = 1
end
end
end
if Object:IsA("Decal") and Object.Parent.Name == "FaceHead" then
Object.Transparency = 0
end
if Object:IsA("Motor6D") and Object.Name ~= "Handle" and Object.Name ~= "Neck" then
local Socket = Instance.new("BallSocketConstraint", Object.Parent)
local Attachment0, Attachment1 = Instance.new("Attachment"), Instance.new("Attachment")
Attachment0.CFrame, Attachment1.CFrame = Object.C0, Object.C1
Attachment0.Parent, Attachment1.Parent = Object.Part0, Object.Part1
Socket.Attachment0, Socket.Attachment1 = Attachment0, Attachment1
Socket.LimitsEnabled = true
Socket.TwistLimitsEnabled = true
Socket.Enabled = false
if Socket.Parent.Name == "HumanoidRootPart" then
Socket.TwistLimitsEnabled = false
Socket.UpperAngle = 180
end
end
end
RagdollEntity.Parent = workspace
RagdollHumanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, false)
RagdollHumanoid:ChangeState(Enum.HumanoidStateType.Ragdoll)
RagdollHumanoid.PlatformStand = true
for _, v in RagdollHumanoid.Animator:GetPlayingAnimationTracks() do v:Stop(0) end
for _, Thing in pairs(RagdollEntity:GetDescendants()) do
if Thing:IsA("Motor6D") and Thing.Name ~= "Handle" and Thing.Name ~= "Neck" then
Thing.Enabled = false
elseif Thing:IsA("BallSocketConstraint") then
Thing.Enabled = true
end
end
local RagdollAttachment = Entity.HumanoidRootPart.RootAttachment:Clone()
RagdollAttachment.Name = "RagdollAttachment"
RagdollAttachment.Axis = Vector3.new(0, 1, 0)
RagdollAttachment.SecondaryAxis = Vector3.new(0, 0, -1)
RagdollAttachment.Parent = Entity.HumanoidRootPart
local Constraint = Instance.new("CylindricalConstraint")
Constraint.Attachment0 = RagdollHRP.RootAttachment
Constraint.Attachment1 = RagdollAttachment
Constraint.Parent = RagdollHRP
Constraint.LimitsEnabled = false
end)
Edit as this might be unclear to somebody: I want to know if there are any specific constraints or services that can accomplish what I’m trying to do.