✓ Accepted answer
What I would do in this event is create a connections table and a regular table.
The regular table would be equivalent to your 'storages' table.
I made an example to test how this can work:
connections = {}
storages = {}
setmetatable(storages, {__newindex = function(self,ind,val)
connections[#connections + 1] = val.ChildAdded:connect(function(a)
print("Did it!")
end)
end})
function insert(tab,thing)
tab[#tab + 1] = thing
end
local f = Instance.new("Folder",workspace)
insert(storages,f)
wait(1)
Instance.new("Script",f)
In the test scenario above, each time something new is added to 'storages', it gives it an event which is added to connections. I do believe I am over-complicating what you may be asking, but this is a good concept on how to add new things to a table with an event without having to constantly loop and reset the connections.
If I didn't get what you were asking for, PLEASE comment. I truly am here to help.
2 comments
Thanks for the help! I'll look in more on metatables and tell you if I have any more questions. I didn't realize we had to get this complicated to fix my script, but nonetheless I thank you for your help and will start the learning process. (I probably should know how to use metatables anyway :3 )
After taking a couple days off from scripting I came back and finished implementing the script into my game! THANK YOU for the help. Metatables was something I tried to learn before but was unable to grasp at the concept, but your help here has given me a boost into understanding metatables. I hope someday I can return the favor!