Attempting to make a script that looks into a tag when a object is spawned and then when the ProximityPrompt is triggered, it’ll fire the event, but the way I’m going about it isn’t efficient and just reports errors due to it running multiple times.
CollectionService:GetInstanceAddedSignal("PartDrop"):Connect(function()
for i, model in pairs(CollectionService:GetTagged("PartDrop")) do
model.Parent:FindFirstChild("ProximityPrompt").Triggered:Connect(function()
model.Parent.Parent.Parent:Destroy()
partCount -= 1
end)
end
end)
You’re updating it for every single PartDrop when just one is added.
Each time one is added, you create a new connection for all of them which builds up and creates big memory leaks over time.
Here’s how you can fix it:
Only create new connections for the part that’s added
Disconnect connections for parts when they are removed
You can do this by updating 2 tables, one of instances in game and one of connections; or just a dictionary with instance as key and connection as value. Disconnect and remove the connection when the part is removed, and reconnect it when the part is added.
Disconnect just seemed to halt every other prompt when I used it, with the code I’m trying to do multiple can spawn at once which is why I’m trying to make it so whenever those ProximityPrompts are activated it’ll only act upon that one specific part rather than multiple times, since the part is supposed to be destroyed, if there’s a better way of doing that please inform me