Multiple Proximity Prompt detector

Hi everyone, i’m trying to set multiple proximity prompts on parts inside a folder like this

for i,v in ipairs(Workspace.Folder:GetChildren()) do
	
	Prompt = Instance.new("ProximityPrompt")
	Prompt.Name = "Prompt"
	Prompt.Parent = v
	Prompt.HoldDuration = 1
	Prompt.ObjectText = "Pick up"

end

At this point based on how much parts you have in Folder the script will spawn prompts in every part having for example 10 parts with a prompt for everyone

Now, if i use

Prompt.Triggered:Connect(function(player)
    print("Hello")
end)

the only prompt that will fire is the last one because of the for loop and the others will just not work.

How can i fire every prompt instead of just the last one?

You could put a proximity prompt in the replicated storage with a script like this inside of it. Then, instead of making a new one, you just clone the proximity prompt into the parts.

local prompt = game:GetService("ReplicatedStorage").ProximityPrompt:Clone()

for i,v in ipairs(Workspace.Folder:GetChildren()) do
	Prompt.Parent = v
end

Doing like this then the Original prompt gets cloned inside every part with his script, doesn’t it become too much laggy with 100-200 parts?

I don’t know if instances make the game laggy if they have scripts inside, however since they all have proximity prompts inside, I don’t think this makes it a lot more laggy than it already is. Maybe you can try it and compare the performance.

I’d probably either switch the folder for a model and make a PrimaryPart so you could do this:

local Prompt = Instance.new("ProximityPrompt")	
Prompt.Name = "Prompt"	
Prompt.Parent = workspace.Model.PrimaryPart
Prompt.HoldDuration = 1
Prompt.ObjectText = "Pick up"

Or, if you don’t want to do that, find a random part with

Folder:FindFirstChildOfClass("BasePart")
1 Like