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 9 years ago
01function Touch()
02 
03    game.Workspace.Player["Right Arm"]:Destroy()
04    wait(1)
05    game.Workspace.Player["Left Arm"]:Destroy()
06    wait(1)
07    game.Workspace.Player["Left Leg"]:Destroy()
08    wait(1)
09    game.Workspace.Player["Right Leg"]:Destroy()
10    wait(4)
11    game.Workspace.Player["Head"]:Destroy()
12 
13end
14 
15script.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
9 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

01function Touch(hit)
02    --Make sure it's a player
03    if hit.Parent:FindFirstChild("Humanoid") then
04        char = hit.Parent
05        char["Right Arm"]:Destroy()
06        wait(1)
07        char["Left Arm"]:Destroy()
08        wait(1)
09        char["Left Leg"]:Destroy()
10        wait(1)
11        char["Right Leg"]:Destroy()
12        wait(4)
13        char["Head"]:Destroy()
14    end
15end
16 
17script.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 — 9y
Ad

Answer this question