Modify Multiple Proximity Prompts from 1 Script

  1. What do I want to achieve?
    I want to create a variable that contains multiple models, So I will be able to modify all of their Proximity Prompt properties from 1 script without creating many variables for each and every single one of them.

  2. What is the issue?
    It would only work on ONE model in the workspace
    image image

  3. What solutions have I tried so far?

This is the current working script

local Tool = script.Parent
local ProximityPrompt = game:GetService("ProximityPromptService")
local LavHarvest = workspace.Lavender.leaves.LavenderHarvest

Tool.Equipped:Connect(function()
	LavHarvest.Enabled = true
end)
Tool.Unequipped:Connect(function()
	LavHarvest.Enabled = false
end)

return

but for what I tried of messing around with multiple methods I found on the dev forum. but I haven’t managed to get it to work

Any assistance is appreciated,
Thanks.

1 Like

I have once done it with collectionserice. You could search in that direction and I can’t copy-paste the code in here because I’m on a mobile device.

Use CollectionService, especially tags.

This plugin will help you select instances and add a tag to them otherwise AddTag(instance, string tag) will add to the tag group.

GetTags(string tag) returns a table of instances in that tag group.
Simply loop through it and do your code.

You could also just put all of the Lavender in a folder and just loop through all of the children of the folder like this.

local Tool = script.Parent
local ProximityPrompt = game:GetService("ProximityPromptService")
local LavFolder = --Define path to folder here

Tool.Equipped:Connect(function()
    for i, lavender in pairs(LavFolder:GetChildren()) do
          lavender.leaves.LavenderHarvest.Enabled = true
    end
end)
Tool.Unequipped:Connect(function()
	Tool.Equipped:Connect(function()
    for i, lavender in pairs(LavFolder:GetChildren()) do
          lavender.leaves.LavenderHarvest.Enabled = false
    end
end)
end)

Thanks! I usually organize my maps in folders so using this method is very helpful to me.
There was a mistake in line 10 where you typed a function twice so it kind of bugged:

Tool.Unequipped:Connect(function()
	Tool.Equipped:Connect(function()

but here is the complete working version

local Tool = script.Parent
local ProximityPrompt = game:GetService("ProximityPromptService")
local LavFolder = workspace.Lavenders

	Tool.Equipped:Connect(function()
	for i, lavender in pairs(LavFolder:GetChildren()) do
		lavender.leaves.LavenderHarvest.Enabled = true
	end
end)

Tool.Unequipped:Connect(function()
	for i, lavender in pairs(LavFolder:GetChildren())do
		lavender.leaves.LavenderHarvest.Enabled = false
	end
end)

I have also tried Collection Services but it didn’t work out for me for some reason, but this folder method is way better for me personally.

Thanks @XdJackyboiiXd21 !