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

How do i detect certain parts that are touched by a player?

Asked by 5 years ago

Hello i was wondering how do you detect what part of the players character when you touch a part, because i want to create this script that only executes when its touched by a players head.

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Well first we need to make a touched event.

script.Parent.Touched:connect(function(hit)

We add hit, hit is what part of our character touched the brick.

Then we print out "hit"

script.Parent.Touched:connect(function(hit)
    print(hit) --See how we wont add " "? Thats because we dont want a TEXT to print out.
end)

Now to find if a head touches the part we simply add an "if".

script.Parent.Touched:connect(function(hit)
    if hit.Name == "Head" then --We check if the name of the part that touched the brick is head, if it is then..
        print("yes") --It will print out "yes" in the output. You can put here whatever you want.
    end
end)

Good luck.

Ad

Answer this question