Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Creating a table of names and values?

Asked by 2 years ago

I have a script that reads from folders in a folder all values having int value and numbervalue. How do I correctly make them appear in the table with the values: child.Parent.Name, child.Name, child.Value

local tablevalues = {
    NameParent = {
        NameValue = {
            Value = 5
        }
    }
}

for _, child in ipairs(replicatedstorage.ForCopy:GetDescendants()) do
    if child.ClassName == "IntValue" or child.ClassName == "NumberValue" then
        table.insert(tablevalues, {[child.Parent.Name] = {[child.Name]=child.Value}})
    end
end

PRINT HERE

{NameParent = {NameValue = {Value = 5}},
[11] = {HoneyBadger = {Cost = 0}}, 
[12] = {HoneyBadger = {Damage = 150}}, 
[13] = {HoneyBadger = {Firerate = 1}}, 
[14] = {HoneyBadger = {Level = 3}}, 
[15] = {HoneyBadger = {MaxAmmo = 4}}, 
[16] = {HoneyBadger2 = {Cost = 0}}, 
[17] = {HoneyBadger2 = {Damage = 150}},
[18] = {HoneyBadger2 = {Firerate = 1}}, 
[19] = {HoneyBadger2 = {Level = 3}}, 

I managed to transfer it all to the table, but what do I need to add so that if he sees an existing name in the table, say, honey badger, then he adds values to it? And did not create a new honey badger

Answer this question