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

Help with .Touched function?

Asked by
DevWork 80
9 years ago

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.

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

1 answer

Log in to vote
0
Answered by 9 years ago

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)
Ad

Answer this question