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 use a touch function with a certain part?

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

✓ Accepted answer
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

2 comments

0

Thank you.... You forgot to put an end at one of the ifs.. But I fixed it!

0

Heh, my bad. Sorry. Good think you caught that. Lol.

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