Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why doesn't my Ragdoll script correctly function?

Asked by 6 years ago
local partconnections = {
    {Part0 = "LowerTorso", Part1 = "UpperTorso"},
    {Part0 = "LeftUpperArm", Part1 = "LeftLowerArm"},
    {Part0 = "UpperTorso", Part1 = "LeftUpperArm"},
    {Part0 = "RightLowerArm", Part1 = "RightHand"},
    {Part0 = "LeftLowerArm", Part1 = "LeftHand"},
    {Part0 = "RightUpperArm", Part1 = "RightLowerArm"},
    {Part0 = "UpperTorso", Part1 = "RightUpperArm"},
    {Part0 = "LowerTorso", Part1 = "RightUpperLeg"},
    {Part0 = "LowerTorso", Part1 = "LeftUpperLeg"},
    {Part0 = "HumanoidRootPart", Part1 = "LowerTorso"},
    {Part0 = "LeftLowerLeg", Part1 = "LeftFoot"},
    {Part0 = "LeftUpperLeg", Part1 = "LeftLowerLeg"},
    {Part0 = "RightUpperLeg", Part1 = "RightLowerLeg"},
    {Part0 = "RightLowerLeg", Part1 = "RightFoot"},
    {Part0 = "UpperTorso", Part1 = "Head"}
}

local function Ragdoll(c) -- c = character
    local model = Instance.new("Model", workspace.RagdollFolder)
    model.Name = c.Name
    for i,v in pairs(c:GetChildren()) do
        if v:IsA("BasePart") and v.Name ~= "Boombox" and v.Name ~= "HumanoidRootPart" then
            local clone = v:Clone()
            clone.CFrame = v.CFrame
            clone.Parent = model
            clone.Anchored = false
            clone.CanCollide = true
            if clone.Name == "Head" then
                if clone:FindFirstChild("BillboardBase") then
                    clone.BillboardBase:Destroy()
                end
                if clone:FindFirstChild("face") then
                    clone.face.Texture = "http://www.roblox.com/asset/?id=25891571"
                end
            end
        elseif v:IsA("Shirt") or v:IsA("Pants") or v:IsA("Humanoid") or v:IsA("BodyColors") or v:IsA("Hat") or v:IsA("Accessory") then
            local clone = v:Clone()
            clone.Parent = model
        end
    end
    if workspace.RagdollFolder:FindFirstChild(c.Name) then
        local ragdoll = workspace.RagdollFolder:FindFirstChild(c.Name)
        for i,v in pairs(ragdoll:GetChildren()) do
            if v:IsA("Hat") or v:IsA("Accessory") then
                for x,d in pairs(v:GetChildren()) do
                    if d:IsA("BasePart") then
                        local weld = Instance.new("Weld", ragdoll:FindFirstChild("Head"))
                        weld.Part0 = ragdoll:FindFirstChild("Head")
                        weld.Part1 = d
                        break
                    end
                end
            else
                for x,d in pairs(partconnections) do
                    if d.Part1 == v.Name then
                        local attach = Instance.new("Attachment", v)
                        local attach2 = Instance.new("Attachment", ragdoll:FindFirstChild(d.Part0))
                        local con = Instance.new("BallSocketConstraint", attach)
                        con.Attachment0 = attach
                        con.Attachment1 = attach2
                    end
                end
            end
        end
    end
end

game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(char)
        char.Humanoid.Changed:connect(function()
            if char.Humanoid.Health <= 0 then
                Ragdoll(char)
            end
        end)
    end)
end)

The cloned character does ragdoll, but it spazzes out all about and doesnt correctly stay in 1 spot like it should (no i'm not talking about anchoring it to make it stay still). Is there something I am doing wrong that makes it spaz out?

0
make the hands, feet, head, and root the only tangible parts. Fixed it when I had that problem. The small parts that overlap caused it to keep bouncing and pick up speed Bellyrium 310 — 6y
0
I made the UpperTorso and LowerTorso non-collidable and it still spazzed around? thehybrid576 294 — 6y
0
Also I didnt clone the HumanoidRootPart so it doesnt have one thehybrid576 294 — 6y

1 answer

Log in to vote
0
Answered by
Bellyrium 310 Moderation Voter
6 years ago

line 56+ Do you end up setting an offset for the attachments? I didn't see it.. Ill copy the code and see if I can figure it out.

0
no i didnt, im not quite sure how attachments work thehybrid576 294 — 6y
Ad

Answer this question