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.
✓ ANSWER ACCEPTED
How do i detect certain parts that are touched by a player?
1 answer
✓ Accepted answer
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.
This discussion is preserved as it was. New answers, comments, and votes are closed.
