Hello!
I am making a game where you shoot a part at enemies, and when the part named "Ray" touches an enemy it should destroy it, but it does not work! (canTouch = true) Here is my Touch Script:
1 | local HRP = script.Parent.HumanoidRootPart |
2 |
3 | HRP.Touched:Connect( function (hit) |
4 | if hit.Name = = "Ray" then |
5 |
6 | script.Parent:Destroy() |
7 |
8 | end |
9 | end ) |
Thank you for helping me!
Basically when trying to get the object of what touched another object you want to find the hit.parent
Here is a fixed script:
1 | local HRP = script.Parent.HumanoidRootPart |
2 |
3 | HRP.Touched:Connect( function (hit) |
4 | if hit.Parent.Name = = "Ray" then |
5 |
6 | script.Parent:Destroy() |
7 |
8 | end |
9 | end ) |
Hope this helps!