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

How do I use a touch function with a certain part?

Asked by
lucas4114 607 Moderation Voter
9 years ago

So I want to use the function I made but only if the part is touched by a part named "Bullet" I have this:

debounce = false

health = script.Parent.Parent.Health

function onTouch(hit)
    if debounce == false then
        debounce = true
        health.Value = health.Value - 1
        debounce = false
    end
end

script.Parent.Touched:connect(onTouch)

So, how do I use the function if only the part that touched it is named "Bullet"?

1 answer

Log in to vote
1
Answered by
Discern 1007 Moderation Voter
9 years ago
debounce = false

health = script.Parent.Parent.Health

function onTouch(hit)
    if debounce == false then
        if hit.Name == "Bullet" then --The conditional statement that checks if the name of the part is Bullet. "hit" is the name of the part that touched script.Parent, which is the part I'm assuming that you want to check.
            debounce = true
           health.Value = health.Value - 1
            debounce = false
        end
end

script.Parent.Touched:connect(onTouch)

If I helped you out, be sure to click the Accept Answer button below my character! :D

0
Thank you.... You forgot to put an end at one of the ifs.. But I fixed it! lucas4114 607 — 9y
0
Heh, my bad. Sorry. Good think you caught that. Lol. Discern 1007 — 9y
Ad

Answer this question