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

My Health and Touch script does not work and does not destroy the model?

Asked by 2 years ago
Edited 2 years ago

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:

1local HRP = script.Parent.HumanoidRootPart
2 
3HRP.Touched:Connect(function(hit)
4    if hit.Name == "Ray" then
5 
6        script.Parent:Destroy()
7 
8    end
9end)

Thank you for helping me!

  • KoalaKo_XD
0
Where is this script running? virushunter9 943 — 2y

1 answer

Log in to vote
-1
Answered by 2 years ago

Basically when trying to get the object of what touched another object you want to find the hit.parent

Here is a fixed script:

1local HRP = script.Parent.HumanoidRootPart
2 
3HRP.Touched:Connect(function(hit)
4    if hit.Parent.Name == "Ray" then
5 
6        script.Parent:Destroy()
7 
8    end
9end)

Hope this helps!

0
Did not work for some reason.. KoalaKo_XD 27 — 2y
Ad

Answer this question