Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I make a part do damage on touch?

Asked by 8 years ago

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

1
OH MY GOD I JUST WROTE A WHOLE ARTICLE FOR YOU THEN MY COMPUTER CHOSE TO RESTART HungryJaffer 1246 — 8y
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. UltraUnitMode 419 — 8y
0
@Ultra I wasnt asking that god people like you always have to take the hard road Clakker200 5 — 8y

2 answers

Log in to vote
0
Answered by
funyun 958 Moderation Voter
8 years ago

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)
Ad
Log in to vote
0
Answered by
drahsid5 250 Moderation Voter
8 years ago

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)

Answer this question