Hello developers! I was wondering how I could have multiple proximity prompt without having to duplicate it everytime.
I have a bunch seats that will contain a proxmity prompt and a script but I think that it would be a pain if I had to go back and change each scripts everytime. I want to know how I could implement it to be a better system.
Make a script that controls everything and put this code in it
local Collection = game:GetService("CollectionService")
local Tag = ""
local function ConnectPart(Part:BasePart)
local ProximityPrompt = script.ProximityPrompt:Clone()
ProximityPrompt.Parent = Part
ProximityPrompt.Triggered:Connect(function(Player)
-- Your code
end)
end
for _, Part in pairs(Collection:GetTagged(Tag)) do
ConnectPart(Part)
end
Collection:GetInstanceAddedSignal(Tag):Connect(ConnectPart)
the ProximityPrompt that must be placed in each part put it below the script, select all the parts that will have the ProximityPrompt and then in the command bar write this
for _, v in pairs(game:GetService("Selection"):Get()) do
game:GetService("CollectionService"):AddTag(v, Tag)
end
it will put the tag to what you select and replace Tag with the name of the tag.
Create a Script and put it in game.ServerScriptService. Add the code below into the new Script.
Copy one of the ProximityPrompt and one of the sitanim objects and put them in the new Script.
Copy the code of one of your scripts and paste it below where it says ‘–Paste the code here!–’.
Make sure you replace all occurrences of ‘script.Parent’ with ‘Seat’ in your code.
Delete all of the other sitanim, ProximityPrompt, and Script Objects in all of your Prompt Sit seats.
The one script you created will now add a copy of the Prompt and animation to each seat. And it will run the same code on each seat automatically when the server starts.
function SeatScript(Seat)
--Make sure you replace all occurrences of 'script.Parent' with 'Seat' in your code.
--Paste the code here!--
end
--------------
local WorkspaceChildren = workspace:GetDescendants()
for i, Seat in pairs (WorkspaceChildren) do
if Seat.Name == "Promp Sit with animations" then
script.ProximityPrompt:Clone().Parent = Seat
script.sitanim:Clone().Parent = Seat
--This will run your script when the server starts.
SeatScript(Seat)
end
end