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

How to grab specific value in an Array?

Asked by 5 years ago

Hello, Current working on an inventory UI

I am not sure on how to grab the specific value, to equip. Aka, a weapon.

Currently, I can equip any tool in my backpack cause it has the same but how would I grab the key and value of a specific object in my table?

local Items = {}

local function UpdateItems()
    UI.Backpack:ClearAllChildren()
    for _,ItemObj in pairs(Player.Backpack:GetChildren()) do
        if GameItems:FindFirstChild(ItemObj.Name) then
            table.insert(Items, ItemObj)
        end
    end
end

Would it be just be Items[I]?

0
You should look into dictionaries - this way you can extract specific array elements without needing any kind of loop. I usually opt for dictionary utilization over some extraction algorithm. SummerEquinox 643 — 5y
0
ok, will do. Thank you. Decimaprism 65 — 5y

1 answer

Log in to vote
1
Answered by
Trew86 175
5 years ago

Yes, if you did an if/then expression to return the value if it's the right thing, you would just say:

return Items[i]
Ad

Answer this question