Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to destroy Player body parts?

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

✓ Accepted answer

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.

1 comment

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

This discussion is preserved as it was. New answers, comments, and votes are closed.