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

how do I make someones humanoid take damage when they touch a part named "SmokeE"?

Asked by 7 years ago
function onTouch(Part)
Part.Parent:TakeDamage(4)
end
script.Parent.Touched:connect(onDamage)

2 answers

Log in to vote
0
Answered by
1N0body 206 Moderation Voter
7 years ago

Need more information. This is a simple script which searches for a Humanoid and then gives damage(with debounce).

local touched = false
script.Parent.Touched:connect(function(part)
    if not touched then
        touched = true
        local humanoid = part.Parent:findFirstChild('Humanoid')
        if humanoid then
        humanoid:TakeDamage(4)
        end
    touched = false
    end
end)
Ad
Log in to vote
0
Answered by 7 years ago

You messed up a bit by having the function named "onTouch" and having the .Touched:connect(onDamage). To fix this all you have to do is this:

function onTouch(Part)
Part.Parent:TakeDamage(4)
end
script.Parent.Touched:connect(onTouch)

That should fix your script.

Answer this question