i’m currently using a simple script to switch from
workspace.Folder:GetChildren()
--output vvv
[1] = One
[2] = One
[3] = Two
[4] = One
[5] = One
[6] = Two
to
[One] = 4
[Two] = 2
using
local otherTable = {"foo", "foo", "bar", "foo", "bar"}
local count = {}
for _,v in ipairs(otherTable) do
-- count[v] may be nil.
count[v] = (count[v] or 0) + 1
end
From another tread, it works fine and i have no problems about it but i would expand his selection because every part inside the workspace.Folder every part has an attribute called "Attribute_One" wich changes on every part
I would like to recieve an output of the amounts based on the Attributes value match
let’s say i have 5 parts with this names and attributes
I think this is what you want. Not tested. Note this does not check the type of attribute before updating amount.
local function GetCountOfObjects(objects)
local count = {}
local function GetValue(i, v)
for index, value in ipairs(count) do
if value.name == i and value.value == v then
return value
end
end
end
for i, v in ipairs(objects) do
for name, value in pairs(v:GetAttributes()) do
local get = GetValue(name, value)
if not get then
get = {
name = name,
value = value,
amount = 0
}
count[#count + 1] = get
end
get.amount += 1
end
end
return count
end
-- Print in your format
local t = GetCountOfObjects(workspace:GetChildren())
for _, v in ipairs(t) do
print(('[%s] = %d, %s'):format(v.name, v.amount, tostring(v.value)))
end
I’m using a new place to test it out with this parts
The output actually doesn’t return a list based also on Names but only on amount and values
This is the script copy+pasted in the new script
I have been thinking about a solution for about two days before turning to the forum, I thank you infinitely for your help and sorry if I was not clear in the explanation of the thread