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

How to make this only work with humanoids?

Asked by 10 years ago

This script is supposed to remove it's parent when someone touches it. As of now, it removes itself when anything touches it. I was wondering if it was possible to make it remove itself ONLY when a humanoid touches it.

function touch()
    script.Parent:remove()
end

script.Parent.Touched:connect(touch)

1 answer

Log in to vote
0
Answered by 10 years ago
script.Parent.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        hit:Destroy()
    end
end)

This will destroy anything that touches it as long as there is a object called Humanoid inside the part's parent

Ad

Answer this question