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

Touch Function. HALP?

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

1 comment

0

Use :Destroy() NOT remove!!! (==""Head") is wrong (part.Name =="Head") needs to be there.

1 answer

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)

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