How to check which object (in a table) an event was fired for

Hey, I’ve got a table with proximity prompts in it (each are supposed to do different things). Is there a way of detecting if any of those proximity prompts have been triggered (in the table) and if so, which one was triggered?

I think this would be a lot tidier than it being in separate scripts and I’m sure there is a way to do it, just not sure how.

Thanks in advance!

local prompts = workspace:WaitForChild("PromptFolder"):GetDescendants()

for _, prompt in ipairs(prompts) do
	if prompt:IsA("ProximityPromot") then
		prompt.Triggered:Connect(function()
			print(prompt.Parent.Name)
			local part = prompt.Parent
			--do more stuff here
		end)
	end
end

Basically, just have the prompts and their parents all in a single folder than use the above to connect the same or potentially different callback functions to each, through which you can determine which prompt has been triggered when any prompt has been triggered.

1 Like

Oh, this is really helpful, thanks! Stuff will be a lot easier now.