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

How would I make a part do damage on touch?

I know you would do the function onTouch then call it but how do I make the part in workspace detect your humanoid???

3 comments

1

OH MY GOD I JUST WROTE A WHOLE ARTICLE FOR YOU THEN MY COMPUTER CHOSE TO RESTART

0

Were not here to work for you, It would be better if you gave us something that you have problems with not How to make this and that.

0

@Ultra I wasnt asking that god people like you always have to take the hard road

2 answers

✓ Accepted answer

The Touched event tells you what part is touching. If that part is someone's leg, we can get the parent (the character model) and from there get the Humanoid.

script.Parent.Touched:connect(function(part)
	if part.Parent:FindFirstChild("Humanoid") then
		part.Parent.Humanoid:TakeDamage(30)
end)

Or

function AFunctionIMadeToConnectToTheTouchedEvent(ThePartThatTouched)
	if ThePartThatTouched.Parent:FindFirstChild("Humanoid") then
		ThePartThatTouched.Parent.Humanoid:TakeDamage(30)
	end
end

script.Parent.Touched:connect(AFunctionIMadeToConnectToTheTouchedEvent)

It's pretty simple, You call the touched event, if there's a humanoid take damage

script.Parent.Touched:connect(function(hit)
 if hit.Parent:FindFirstChild("Humanoid ") then
  hit.Parent.Humanoid:TakeDamage(15)
 end
end)

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