How to make a script work on multiple parts

  1. What do you want to achieve?
    I have this script here but it only works on one model, I wanna try and make it so I can duplicate the model and it will still work for both.

  2. What solutions have you tried so far?
    Trying to look after stuff with collection service, but I tried and it doesn’t work for me.


local proximity = workspace.InfoBox1.P1.ProximityPrompt
local PPP = game:GetService("ProximityPromptService")


proximity.Triggered:Connect(function()
	local GUI = script.Parent:WaitForChild("InfoBoxGui")
	GUI.Enabled = not GUI.Enabled
end)

local GUI = script.Parent:WaitForChild("InfoBoxGui")
GUI.TextButton.Activated:Connect(function()
		GUI.Enabled = not GUI.Enabled
end)

	

image

If you can help, thank you!

This line seems to be what makes one different from another:

local proximity = workspace.InfoBox1.P1.ProximityPrompt

So maybe rename InfoBox1.P1 for each copy or maybe just replace InfoBox1.P1 with: script.parent.ProximityPrompt and put the script inside the model.

Tried that but it doesn’t work

Try this:

– SERVER SCRIPT | Located inside part named InfoBox1

local proximity = script.Parent.ProximityPrompt
local PPP = game:GetService("ProximityPromptService")
proximity.Triggered:Connect(function(player)
local gui = player.PlayerGui.SampleGui
gui.Enabled = not gui.Enabled
end)

– CLIENT/LOCAL SCRIPT | inside StarterGui/SampleGui/SampleFrame/SampleTextButton

local gui = script.Parent.Parent.Parent
local button = script.Parent
button.Activated:Connect(function()
print("Button Activated")
gui.Enabled = not gui.Enabled
end)

I tested it and it works with multiple parts in workspace.