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

Why is this script erroring out?

Asked by 10 years ago

When I run the script it errors out saying that there is a problem with the connection line.

Players.Player1.Backpack.Ragdoll:169: attempt to index global 'Humanoid' (a nil value) - Script 'Players.Player1.Backpack.Ragdoll', Line 169 - stack end

bounce = 0

function OnEntered(Player)
    while Player.Character == nil do 
        wait()
    end
    Character = Player.Character
    Humanoid = Character.Humanoid
    wait(1)

function OnDeath()
    if bounce > 0 then return end
    bounce = 1
    Character.Archivable = true
    chrclone = Character:clone()
    Character.Archivable = false
    ch = Character:GetChildren()
    for i = 1,#ch do
        if ch[i].ClassName == "Part" or ch[i].ClassName == "Hat" then
            ch[i]:remove()
        end
    end
    Character = chrclone
    script.Parent = Character
    Character.Name = ""
    Character.Head.face:remove()
    script.face:clone().Parent = Character.Head
    Character.Parent = Workspace
    Torso = Character.Torso
---[ragdoll script]---
end
    wait(10)
    Character:remove()
end end

Humanoid.Died:connect(OnDeath)  <--- Line 169

Can any one tell me why its doing this and how to fix it?

2 answers

Log in to vote
0
Answered by
Nickoakz 231 Moderation Voter
10 years ago

First of all. The Humanoid is inside a function, so trying to call humanoid outside a function wont work..

bounce = 0
function OnEntered(Player)
    while Player.Character == nil do 
        wait()
    end
    Character = Player.Character
    Humanoid = Character:WaitForChild("Humanoid")
    Humanoid.Died:connect(function()
        if bounce > 0 then return end
        bounce = 1
        Character.Archivable = true
        chrclone = Character:clone()
        Character.Archivable = false
        ch = Character:GetChildren()
        for i = 1,#ch do
            if ch[i].ClassName == "Part" or ch[i].ClassName == "Hat" then
                ch[i]:remove()
            end
        end
        Character = chrclone
        script.Parent = Character
        Character.Name = ""
        Character.Head.face:remove()
        script.face:clone().Parent = Character.Head
        Character.Parent = Workspace
        Torso = Character.Torso
        ---[ragdoll script]---
        wait(10)
        Character:remove()
        bounce = 0
    end)
end
Ad
Log in to vote
0
Answered by 10 years ago

Ok, after adding your edits and testing, the script does not work and doesn't even output an error. Perhaps I should give you the full thing.

bounce = 0
function OnEntered(Player)
    while Player.Character == nil do
        wait()
    end
    Character = Player.Character
    Humanoid = Character:WaitForChild("Humanoid")
    Humanoid.Died:connect(function()
        if bounce > 0 then return end
        bounce = 1
        Character.Archivable = true
        chrclone = Character:clone()
        Character.Archivable = false
        ch = Character:GetChildren()
        for i = 1,#ch do
            if ch[i].ClassName == "Part" or ch[i].ClassName == "Hat" then
                ch[i]:remove()
            end
        end
        Character = chrclone
        script.Parent = Character
        Character.Name = ""
        Character.Head.face:remove()
        script.face:clone().Parent = Character.Head
        Character.Parent = Workspace
        Torso = Character.Torso
    if Torso then
        local Head = Character:FindFirstChild("Head")
        if Head then
            local Neck = Instance.new("Weld")
            Neck.Name = "Neck"
            Neck.Part0 = Torso
            Neck.Part1 = Head
            Neck.C0 = CFrame.new(0, 1.5, 0)
            Neck.C1 = CFrame.new()
            Neck.Parent = Torso
        end
        local Limb = Character:FindFirstChild("Right Arm")
        if Limb then

            Limb.CFrame = Torso.CFrame * CFrame.new(1.5, 0, 0)
            local Joint = Instance.new("Glue")
            Joint.Name = "RightShoulder"
            Joint.Part0 = Torso
            Joint.Part1 = Limb
            Joint.C0 = CFrame.new(1.5, 0.5, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0)
            Joint.C1 = CFrame.new(-0, 0.5, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0)
            Joint.Parent = Torso

            local B = Instance.new("Part")
            B.TopSurface = 0
            B.BottomSurface = 0
            B.formFactor = "Symmetric"
            B.Size = Vector3.new(1, 1, 1)
            B.Transparency = 1
            B.CFrame = Limb.CFrame * CFrame.new(0, -0.5, 0)
            B.Parent = Character
            local W = Instance.new("Weld")
            W.Part0 = Limb
            W.Part1 = B
            W.C0 = CFrame.new(0, -0.5, 0)
            W.Parent = Limb

        end
        local Limb = Character:FindFirstChild("Left Arm")
        if Limb then

            Limb.CFrame = Torso.CFrame * CFrame.new(-1.5, 0, 0)
            local Joint = Instance.new("Glue")
            Joint.Name = "LeftShoulder"
            Joint.Part0 = Torso
            Joint.Part1 = Limb
            Joint.C0 = CFrame.new(-1.5, 0.5, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0)
            Joint.C1 = CFrame.new(0, 0.5, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0)
            Joint.Parent = Torso

            local B = Instance.new("Part")
            B.TopSurface = 0
            B.BottomSurface = 0
            B.formFactor = "Symmetric"
            B.Size = Vector3.new(1, 1, 1)
            B.Transparency = 1
            B.CFrame = Limb.CFrame * CFrame.new(0, -0.5, 0)
            B.Parent = Character
            local W = Instance.new("Weld")
            W.Part0 = Limb
            W.Part1 = B
            W.C0 = CFrame.new(0, -0.5, 0)
            W.Parent = Limb

        end
        local Limb = Character:FindFirstChild("Right Leg")
        if Limb then

            Limb.CFrame = Torso.CFrame * CFrame.new(0.5, -2, 0)
            local Joint = Instance.new("Glue")
            Joint.Name = "RightHip"
            Joint.Part0 = Torso
            Joint.Part1 = Limb
            Joint.C0 = CFrame.new(0.5, -1, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0)
            Joint.C1 = CFrame.new(0, 1, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0)
            Joint.Parent = Torso

            local B = Instance.new("Part")
            B.TopSurface = 0
            B.BottomSurface = 0
            B.formFactor = "Symmetric"
            B.Size = Vector3.new(1, 1, 1)
            B.Transparency = 1
            B.CFrame = Limb.CFrame * CFrame.new(0, -0.5, 0)
            B.Parent = Character
            local W = Instance.new("Weld")
            W.Part0 = Limb
            W.Part1 = B
            W.C0 = CFrame.new(0, -0.5, 0)
            W.Parent = Limb

        end
        local Limb = Character:FindFirstChild("Left Leg")
        if Limb then

            Limb.CFrame = Torso.CFrame * CFrame.new(-0.5, -2, 0)
            local Joint = Instance.new("Glue")
            Joint.Name = "LeftHip"
            Joint.Part0 = Torso
            Joint.Part1 = Limb
            Joint.C0 = CFrame.new(-0.5, -1, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0)
            Joint.C1 = CFrame.new(-0, 1, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0)
            Joint.Parent = Torso

            local B = Instance.new("Part")
            B.TopSurface = 0
            B.BottomSurface = 0
            B.formFactor = "Symmetric"
            B.Size = Vector3.new(1, 1, 1)
            B.Transparency = 1
            B.CFrame = Limb.CFrame * CFrame.new(0, -0.5, 0)
            B.Parent = Character
            local W = Instance.new("Weld")
            W.Part0 = Limb
            W.Part1 = B
            W.C0 = CFrame.new(0, -0.5, 0)
            W.Parent = Limb

        end
        --[
        local Bar = Instance.new("Part")
        Bar.TopSurface = 0
        Bar.BottomSurface = 0
        Bar.formFactor = "Symmetric"
        Bar.Size = Vector3.new(1, 1, 1)
        Bar.Transparency = 1
        Bar.CFrame = Torso.CFrame * CFrame.new(0, 0.5, 0)
        Bar.Parent = Character
        local Weld = Instance.new("Weld")
        Weld.Part0 = Torso
        Weld.Part1 = Bar
        Weld.C0 = CFrame.new(0, 0.5, 0)
        Weld.Parent = Torso
        --]]
    end
    wait(10)
    Character:remove()
    bounce = 0
end)
end

This was after adding your edits.

Answer this question