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

Help with .Touched function?

This script is currently removing the HumanoidRootPart and also destroying various parts of the character as on touched, but what I need it to do is to just remove the HumanoidRootPart. Please help!

script.Parent.Touched:connect(function(hit)
	if hit.Parent:FindFirstChild("HumanoidRootPart") then
		hit:Destroy()
	end
end)

Thanks in advance.

1 comment

2

Just :Destroy() the HumanoidRootPart instead of Hit. Should be EXTREMELY easy to figure out if you truly understand the above code you wrote. 

1 answer

Line 3 is where it's all going wrong. In line 3, you are destroying the thing that touched the part, taht's not what you want.

script.Parent.touched:connect(function(hit) --Something touches the brick
Part = hit.Parent:FindFirstChild("HumanoidRootPart") --Finds the RootPart
if Part then Part:Destroy() end --If what you are looking is there, then destroy it.
end)

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