Are there any faster ways to do add attributes?

As the title says, its pretty hard to add multiple attributes to hundreds of object manually and I know you may say that just use value object but I heard somewhere that attributes are better than values in terms of optimization (correct me if I’m wrong). So are there any plugins or tricks to add them faster?

You’re right that attributes can be more optimized than value objects in some cases, especially for performance, so it’s a good idea to use them when possible. and one of the easiest ways to add attributes in bult is by using a script, I’ll provide an example

local objectsFolder = game.Workspace:WaitForChild("YourFolderName") -- Change this to your folder's name
local attributeName = "YourAttributeName" -- Replace with the attribute name you want to add
local attributeValue = "YourAttributeValue" -- Replace with the desired value

for _, obj in ipairs(objectsFolder:GetChildren()) do
    if obj:IsA("Part") then -- Change this check based on your specific needs
        obj:SetAttribute(attributeName, attributeValue)
    end
end

You can easily run this script as a local script, but make sure to change the folder name, attribute name, and the value to your own. You were also asking if there are any plugins that can help with that, and if you do prefer a plugin you can look into “Model Tools” or “Attribute editor” hopefully they can help you manage attributes

1 Like

This is good solution, but you see I have a system like towers enemies and stuff and all towers are in one folder and all enemies are in other folder and all enemies and towers are different in appereance, model, weapons and almost everything so the thing is that there’s not a single similar specific thing in those folder so this will work in any other specific things but not for me now.

Oh I see, I’m really unsure how I could help in a different way sorry!!

1 Like

Its ok, and why are you sorry bro it will help me to make some other system and other project don’t be sorry you still helped me : D

I’m glad I could help you! Goodluck on all your projects hope you succussed on the platform

1 Like

Tag your instances then using collectionService you will get all tagged instances and do something with them.

1 Like

Idk how tags will help because as I said I have multiple different towers with all different use all with different attributes so I don’t think this will work. I want to add attributes faster.

You can get tagged instances from anywhere no matter their parent. Maybe I misunderstood the question, did you want to basically add attributes to various instances faster? Are these attributes unique or are they the same?

1 Like

their name are same but their values are unique.

Yes.

Do you mean like they would have an attribute called “Car” but their values were different car models? What are these unique attributes?

1 Like

for example this:

Value : 1
this is a different object with the same attribute but with different value
Value : 2

these numbers are value and they are different so i call them unique value
(sorry if this is confusing)

Are those unique values based around something like money needed to purchase that unit? If they’re very unique like object A has Name: Bob, object B has Name: John and another one has Name: Jane then you might need to manually set them.

1 Like

Aw man that’s what I thought :C well thanks for your reply! would be great if someone make a plugin for it I would pay 10,000,000$ for it.

1 Like

If it was something like a unit called “UnitA” costs 10 gold then there’s a solution.

You could do this:

local CollectionService = game:GetService("CollectionService") 

local Units = {
 ["unitA"] = 10
}
 
for _, TaggedInstance in CollectionService:GetTagged("tag") do
 local Cost = Units[TaggedInstance.Name]
 if not Cost then continue end
 TaggedInstance:SetAttribute("Cost", Cost) 
end

If this still isn’t what you were looking for then im sorry I couldn’t help you get to a more efficient solution :pensive:

1 Like

actually this actually works for me thanks!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.