Start a function when any proximity prompt from a table is held

So far I have this:

promptTable = {}

for r,x in ipairs(script.Parent:GetChildren()) do
	if x.Name == "Trash" then
		table.insert(promptTable,x.CleanTrash) -- x.CleanTrash is always a ProximityPrompt
	end
end

-- promptTable is now filled with a lot of proximity prompts.

function trigger()

end
-- write a line of code here

What I want is, in the line of code here, how do I start the trigger function every single time ANY proximity prompt from promptTable is held down?

1 Like
for i,v in pairs(promptTable) do
     v.Triggered:Connect(function()
         --// what you want to make
    end)
end
1 Like

That is not memory efficient.

for i,v in pairs(promptTable) do
     v.Triggered:Connect(connectItToYourFunctionInstead)
end

Connect it to your function instead. This method uses up less memory because it doesn’t create a function each time.

1 Like

yeah that’s faster but makes the same job

1 Like

This is good so far, but how do I then get what proximity prompt was triggered from the function?

I guess in that case you would need to directly connect it to a function with the prompt itself as an argument.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.