1 | script.Parent.Touched:Connect( function (hit) |
2 | if hit.Parent:FindFirstChild ( "Humanoid" ) then |
3 | hit.Parent:BreakJoints() |
4 | end |
5 | end |
1 | function onTouch(part) |
2 | local humanoid = part.Parent:FindFirstChild( "Humanoid" ) |
3 | if (humanoid ~ = nil ) then -- if a humanoid exists, then |
4 | humanoid.Health = 0 -- damage the humanoid |
5 | end |
6 | end |
7 |
8 | script.Parent.Touched:connect(onTouch) |
This should work:
1 | script.Parent.Touched:connect( function (hit) |
2 | if hit and hit.Parent and hit.Parent:FindFirstChild( "Humanoid" ) then |
3 | hit.Parent.Humanoid.Health = 0 |
4 | end |
5 | end ) |
Please contact me when this is not what you ment or if it doesn't work.
Since you only gave info in your title, I can only go off that. But, for what the title is asking, this is what I do:
1 | script.Parent.Touched:Connect( function (hit) |
2 | local Char = hit:FindFirstAncestorOfClass( "Model" ) |
3 |
4 | Char.Humanoid.Health = Char.Humanoid.Health - Char.Humanoid.Health |
5 | end |
Obviously, this wouldn't work if you put another model in-between the character and hit. But the reason I do this, is because if an accessory touched the part, hit.Parent wouldn't work. So this way, it checks for the first model that hit is in.