How to connect an event to an array?

Hello! I am wondering on how I commit an event, for example .Touched, to an array. Basically, when any part in the Array is touched, it invokes a function.

Purpose: The purpose for that in my case is to reduce lag, as less scripts will be running.

Simplified: How to connect an event to an array.

Do you mean looping through the parts and connecting them to an event?

for _, part in pairs(array) do
	part.Touched:Connect(function(hit)
		print(hit)
	end)
end
1 Like

If I plug that to fire a function, will it fire the function every time the part is hit or if the part is hit during the loop?

Alright, I got it!

It will everytime it is hit, you can also use collection service, for example, you can give all your kill bricks the tag of “Kill” and then loop through the objects with that tag, then connect the function and what you want to do with it, etc.

1 Like