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

How do I make a part kill the person that has touched it

I have tried this and it didn't work :C please help me with this

function hit (h)
	h.health = 0
end

game.Workspace.Part.Touched:connect(hit)

and the output said "health is not a valid member of part" or something

2 answers

✓ Accepted answer

Health is not a member of part, it is a part of Part.Parent.Humanoid

function hit (h) 
	if h.Parent:findFirstChild("Humanoid") then
		if h.Parent.Humanoid.Health ~= 0 then --Kinda a debounce
			h.Parent,Humanoid.Health = 0
		end 
	end
end
game.Workspace.Part.Touched:connect(hit) 

3 comments

1

It is not recommended to Cap lock here, and no problem :P

0

On line 4, you did h.Parent,Humanoid instead of h.Parent.Humanoid, and you didn't capitalize Health.

0

:P

Health isn't actually a thing in your character, it's the Humanoid.

1 comment

0

The thing touching it wouldn't be your character, it would be a part of your character, such as your left leg.

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