How would i index the origin part of touched, if the connections for it are in a table?

Let’s say you have a list of parts. You iterate trough them and connect the Touched event to an arbitrary function, and you store this connection in another table. since if a connection is stored at least somewhere, lua GC won’t get rid of it

So the question is:
How would i index the part that triggered its event in that arbitrary function?

If it’s confusing, here’s code:

function SomeFunction(hit)
	--How do i reference what part triggered this function, in this function?
end

Functions = {} --this is where we store connections
Parts = {} --any part list

for i = 1, #Parts, 1 do
	table.insert(Functions, Parts[i].Touched:Connect(SomeFunction))
end

You can do the same as this to index the part with the connection being triggered.

That’s the thing… you just don’t know which event triggered, and what part triggered it.
If there was a way to check what event in the list triggered the function, then i could just index the part in the other list from the event’s number.

What you posted here only has 1 part, with it’s function clearly defined. Mine has x ammount. (could be 10 or 20 or idk 382)

And i already saw this post.

It should be the same concept even with X amount of parts.

function SomeFunction(hit,partWithEvent)
	--How do i reference what part triggered this function, in this function?
--put another parameter and construct a function with a reference
--to the original part with the touched function
end

local touchedEvents = {} --this is where we store connections
Parts = {} --any part list

for i = 1, #Parts, 1 do
local currentPart = Parts[i]
local touchedEvent = currentPart.Touched:Connect(function(hitPart)
SomeFunction(hitPart,currentPart)
end)
	table.insert(touchedEvents, touchedEvent)
end

1 Like

This actually worked, i think i misunderstood you at first.
Marked as solution, and thank you for your time.