Server can’t access playerGui because they are local instances. You have to basically remake your system to work with the server. I would recommend taking the time to remake the system or simply use your old script. There is no need to iterate when using a function though as it’s redundant.
Inventory.ChildAdded:Connect(function (child)
-- child is the newly added itemFrame in inventory
child.MouseButton1Click:Connect(function()
-- new connection here
end)
end)
This is also means you’d have to add the actual child from elsewhere. Perhaps an external script that it’s purpose is solely to add the itemFrame into the PlayerGui.
Conclusion: You have asked for a more efficient script. I would say you could have a more efficient system.
Here is a script-handled inventory system. Could be a bit advanced but 100000% worth learning it.
ProfileService is also an open source tool for creating inventories and having them save in DataStores as well as take care of all the corner cases for data like autosaving, saving when server shut downs, and more stuff. Try it out as it will also save you the hassle of perfecting your inventory.