Hi! I’m having issues in trying to get the number of children that have certain attributes from a single parent. For example, trying to get the number of folders with attributes, (“Owner”) == “Max”
To visualise, here:
Hi! I’m having issues in trying to get the number of children that have certain attributes from a single parent. For example, trying to get the number of folders with attributes, (“Owner”) == “Max”
To visualise, here:
Create a counter variable, loop through the folder. If the condition is true, simply add to the counter variable. - Will give you the number of children that passes that condition.
Example:
local counter = 0
for _,v in pairs(folder:GetChildren()) do
if v:GetAttribute("Owner") == "Max" then
counter += 1
end
end
I’ve managed to make a script similar to that, however, the issue comes in when there’s multiple owners and I will need a lot of counters. Is there any better technique than simply copying and pasting local counter1, counter2, etc ? In addition, how would I also be able to detect if an attribute is changed that makes the number goes down?
Sorry, not understanding what you mean by multiple owners. Could you provide some code or an example?
Here’s a link to a method you can run that will detect if an attribute has been changed: Instance | Roblox Creator Documentation
Let’s say that I have 10 IntValues, with respective names of the Attribute’s values, such as Max, James, Paul and so on.
How would I make it easier that the loop script be able to identify folders with attributes with the value of those names and increase the number in IntValue. So, then when it loops, for example, it’ll identify that Max has 6 folders, James has 3 folders and etc.
Owner meant the Attribute Value, which is “Owner”.
Apologies, I am currently on mobile. If I’m not mistaken this seems like a great place to utilize dictionaries.
The counter loop above was good, but instead of changing the counter variable, it changes the value of the key. Therefore, allowing you to store multiple owners whilst having separate values under each key. I hoped this helped a bit.
As Coolman26071 said above, dictionaries will work.
Example:
local dictonary = {
["Max"] = 10;
["James"] = 5;
["Paul"] = 3;
}
If you wanted to retrieve a value from the dictonary:
print(dictonary["Max"]) or print(dictonary.Max)
More information on key, value pairs is here: https://education.roblox.com/en-us/resources/intro-to-dictionaries---series
All the best,
deshea9