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

Touch Function. HALP?

Asked by 8 years ago

This works...

function onTouched(part)
    if part.Name == "GrassPart" then
        script.Parent:remove()
    end
end

script.Parent.Touched:connect(onTouched)

However, I wanted to add more parts, but it doesn't work. I tried this...

function onTouched(part)
    if part.Name == "GrassPart" or "Head" then
        script.Parent:remove()
    end
end

script.Parent.Touched:connect(onTouched)

How do I make it work with more parts? I know I could just do this, but is there a shortcut?

function onTouched(part)
    if part.Name == "GrassPart" then
        script.Parent:remove()
    end
end

function onTouched(part)
    if part.Name == "Head" then
        script.Parent:remove()
    end
end

script.Parent.Touched:connect(onTouched)

Thanks! I repay you with with my own joke "What job does a plum do? Plumbing." Ha... Ha... Ha... Cough Cough

0
Use :Destroy() NOT remove!!! (==""Head") is wrong (part.Name =="Head") needs to be there. ConnorXV 5 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

just something wrong in or (i think)

function onTouched(part)
    if part.Name == "GrassPart" or part.Name =="Head" then --see this line
        script.Parent:remove()
    end
end

script.Parent.Touched:connect(onTouched)

Ad

Answer this question