Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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:

local HRP = script.Parent.HumanoidRootPart

HRP.Touched:Connect(function(hit)
	if hit.Name == "Ray" then
		
		script.Parent:Destroy()
		
	end
end)


Thank you for helping me!

  • KoalaKo_XD

1 comment

0

Where is this script running?

1 answer

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

Here is a fixed script:

local HRP = script.Parent.HumanoidRootPart

HRP.Touched:Connect(function(hit)
    if hit.Parent.Name == "Ray" then

        script.Parent:Destroy()

    end
end)

Hope this helps!

1 comment

0

Did not work for some reason..

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