0

I am working on a game in Roblox and need a little help finding objects with attribute values. It is a tycoon for anyone here familiar with Roblox. I would like to know how you can find all instances with say the attribute Unlock_ID: 1, and then when you press the corresponding button, it will unlock it, or make it show up on the screen. I know how to make the objects unlock, I just don't know how to get all the objects with that attribute.

To put it more simply:

I want to find all the objects/instances inside a section with a specific attribute and a specific value and put them inside a table.

I hope this makes sense.

  • 2
    Does this answer your question? https://stackoverflow.com/a/71897970/2860267 – Kylaaa Sep 04 '22 at 20:50
  • @Kylaaa Sort of, I saw that before but I don't know how to add it to a table. – ProgrammerGuy Sep 04 '22 at 23:08
  • @Hack.cpp `table.insert`. Also, if the indices don't matter and if the table will be used for checking existence then you can also use the keys of the table to store these – Random Sep 05 '22 at 12:52

1 Answers1

2

You can use a for i,v in ipairs loops along with the Folder:GetChildren() as your iteration directory. Then you can insert the instance (using table.insert(table,element) into a table if their part:GetAttribute('Unlock_ID') is equal to 1. To achieve this, simply do the following:

local partsWithAttribute = {}
local folder = workspace.Folder -- change this to whatever path you want to iterate through

for i,part in ipairs(folder:GetChildren()) do
    if part:GetAttribute('Unlock_ID') == 1 then
        table.insert(partsWithAttribute,part)
    end
end
vxsqi
  • 61
  • 4