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

How to destroy Player body parts?

Asked by 8 years ago
function Touch()

    game.Workspace.Player["Right Arm"]:Destroy()
    wait(1)
    game.Workspace.Player["Left Arm"]:Destroy()
    wait(1)
    game.Workspace.Player["Left Leg"]:Destroy()
    wait(1)
    game.Workspace.Player["Right Leg"]:Destroy()
    wait(4)
    game.Workspace.Player["Head"]:Destroy()

end

script.Parent.Touched:connect(Touch)

Be aware I just started working with more complex Player scripts. I'm sure it's something obvious I'm missing, but I can't seem to find it.

1 answer

Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
8 years ago

Your Problem

You're always destroying the body parts of the same model - Player. What if there is no Player inside of workspace? You have to reference the character according to what the Touched event returns. The Touched event returns whatever was touched.


Code

function Touch(hit)
    --Make sure it's a player
    if hit.Parent:FindFirstChild("Humanoid") then
        char = hit.Parent
        char["Right Arm"]:Destroy()
        wait(1)
        char["Left Arm"]:Destroy()
        wait(1)
        char["Left Leg"]:Destroy()
        wait(1)
        char["Right Leg"]:Destroy()
        wait(4)
        char["Head"]:Destroy()
    end
end

script.Parent.Touched:connect(Touch)

Note: The character will die upon the removal of the 'Head' instance.

0
Thank you very much! Yes, I was convinced it had to do with FindFirstChild, but I just wasn't sure where to put it! :D KingCamembert 57 — 8y
Ad

Answer this question