How can a make a table that has a list of the names of the models inside a folder so that i dont have to manually edit everyhting each time I add a new item to the folder?
Thanks!
local items = game.ReplicatedStorage.Items
local data = {
Level = 1,
Gems = 0,
ItemsOwned = {-------list of items inside folder
nameofiteminsidefolder = false,------
nameofiteminsidefolder = false,
nameofiteminsidefolder = false,
nameofiteminsidefolder = false,
},
}
It’s possible to use GetChildren and iterate through that, adding every Instance to the dictionary.
Yet also, you can Connect on ChildAdded/ChildRemoved to add/remove that Instance from the dictionary:
local ItemsOwned = {}
local Folder = workspace.Folder --// Example
for _, Item in ipairs(Folder:GetChildren()) do --// Use ipairs for arrays
ItemsOwned[Item.Name] = Item
end
Folder.ChildAdded:Connect(function(Child)
ItemsOwned[Child.Name] = Child
end)
Folder.ChildRemoving:Connect(function(Child)
ItemsOwned[Child.Name] = nil --// Setting it to nil is essentially removing it
end)
FYI: If Items were to share the same name then a method involving setting the Instance names to GUIDs (from HttpService) might be a good idea.