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

How do I destroy body parts?

Asked by 4 years ago

so uh yeah i tried this before in some games and it working and since recently its not working my code is:

`script.Parent.Humanoid.Died:Connect(function()
    head:Destroy()
    torso:Destroy()
    hrp:Destroy()
    tla:Destroy()
    tra:Destroy()
    tll:Destroy()
    trl:Destroy()
    mla:Destroy()
    mra:Destroy()
    mll:Destroy()
    mrl:Destroy()
    bla:Destroy()
    bra:Destroy()
    bll:Destroy()
    bll:Destroy()
end)`

im using it to destroy npcs tho new scripter here

oh yeah if u ask why are those things head,hrp or something, i made them variables :D

3 answers

Log in to vote
0
Answered by
pwx 1581 Moderation Voter
4 years ago
Edited 4 years ago

Although you have the right idea, you cannot just type 'torso' or 'head' and the script automatically picks up on what you mean. You have to define on what you want to delete, also instead of using lines of code you can actually use a loop for this.

local NPC = script.Parent
local Humanoid = NPC:WaitForChild('Humanoid')

Humanoid.Died:Connect(function()
    for _,v in pairs(NPC:GetChildren()) do
        if v:IsA('BasePart') or v:IsA('MeshPart') or v:IsA('UnionOperation') -- check if its a part
            v:Destroy() -- destroy any parts found
        end
    end
end)

If you have any other questions feel free to comment below.

0
^ Also supposedly, you don't REALLY need UnionOperations and MeshParts unless you're doing R15 or the NPC has some sort of morph. pwx 1581 — 4y
0
ok i guess i was not clear enuf JustADio 2 — 4y
0
uh sorry i tried it i was not working JustADio 2 — 4y
0
Is the script located inside the NPC? And is the Humanoid located also inside the NPC within' the same Parent? pwx 1581 — 4y
View all comments (4 more)
0
remove ` or v:IsA('MeshPart') or v:IsA('UnionOperation')` because BasePart checks all of those programmerHere 371 — 4y
0
^ Fair enough. I had no idea it did. pwx 1581 — 4y
0
yes it is located inside the NPC and the humanoid too. The script is not working. JustADio 2 — 4y
0
apparently my problems is custom models dont work for me hah anyways thats a nice way to delete body parts thanks! JustADio 2 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

uh i guess i need to give the full script ;-;

local walk = script.Parent.Humanoid:LoadAnimation(script.Walking)
local throw = script.Parent.Humanoid:LoadAnimation(script.Throw)
local head = script.Parent.Head
local torso = script.Parent.Torso
local hrp = script.Parent.HumanoidRootPart
local tla =script.Parent.TopLeftArm
local tll = script.Parent.TopLeftLeg
local mla = script.Parent.MidLeftArm
local mll = script.Parent.MidLeftLeg
local bla = script.Parent.BotLeftArm
local bll = script.Parent.BotLeftLeg
local tra = script.Parent.TopRightArm
local trl = script.Parent.TopRightLeg
local mra = script.Parent.MidRightArm
local mrl = script.Parent.MidRightLeg
local bra = script.Parent.BotRightArm
local brl = script.Parent.BotRightLeg                                                                                                                               

wait(0.001)
walk:Play()

while true do
    wait(10)
    local e = Instance.new("Part",workspace)
    e.Shape = "Ball"
    e.Material = "Neon"
    e.Size = Vector3.new(18.93, 18.93, 18.93)
    e.BrickColor = BrickColor.new("Really red")
    e.CFrame = tla.CFrame
    local f = Instance.new("Part",workspace)
    f.Shape = "Ball"
    f.Material = "Neon"
    f.Size = Vector3.new(18.93, 18.93, 18.93)
    f.BrickColor = BrickColor.new("Really red")
    f.CFrame = tra.CFrame
    wait(0.0001)
    local eweld = Instance.new("Motor6D",e) 
    eweld.Part0 = e
    eweld.Part1 = tla
    local fweld = Instance.new("Motor6D")
    fweld.Part0 = f
    fweld.Part1 = tra
    wait(0.0001)
    throw:Play()
    wait(0.5)
    eweld:Destroy()
    fweld:Destroy()
    e.Touched:Connect(function(p)
        if p.Parent:FindFirstChild("Humanoid") then
            p.Parent.Humanoid.Health = p.Parent.Humanoid.Health -10
            e:Destroy()
        end
    end)
    f.Touched:Connect(function(p)
        if p.Parent:FindFirstChild("Humanoid") then
            p.Parent.Humanoid.Health = p.Parent.Humanoid.Health -10
            f:Destroy()
        end
    end)
end
`script.Parent.Humanoid.Died:Connect(function() 
    head:Destroy()
    torso:Destroy()
    hrp:Destroy()
    tla:Destroy()
    tra:Destroy()
    tll:Destroy()
    trl:Destroy()
    mla:Destroy()
    mra:Destroy()
    mll:Destroy()
    mrl:Destroy()
    bla:Destroy()
    bra:Destroy()
    bll:Destroy()
    bll:Destroy()
    end)

from line 61 to line 76 is the problem. `

Log in to vote
0
Answered by 4 years ago

if brl isn't the issue,as its spaced out. Here's a simple way I delete body parts when you click a button:

Using Local Script:

meep = game.Players.LocalPlayer.Character

script.Parent.MouseButton1Click:Connect(function()
       meep.Head:Destroy()
       meep.Torso:Destroy()
end)

it destroys the local player's head and torso (R6) . Hopefully this example helps you.

Answer this question