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

Mass Touched Event?

Would it be possible to create one script to monitor if any of a group of blocks was touched? This way I wouldn't have to place a script in each part. I have no idea how you would do this but I'll try to explain it with this example that is probably wrong.

for _,v in pairs(workspace.Killers:GetChildren()) do
v.Touched:connect(function(hit)
--etc
end)
end=

1 answer

Yes, what you have works.

I would argue that it would probably be better to organize it a little differently, though:

function toucher( hit, part )
	-- hit is the thing touching part,
	-- part is the thing in "Killers"
end

for _, v in pairs(workspace.Killers:GetChildren()) do
	v.Touched:connect( function(hit)
		toucher( hit, v )
	end)
end

Now you keep your definition of what to do outside of the for loop, where it can be a little cleaner.

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