Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to grab specific value in an Array?

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]?

2 comments

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.

0

ok, will do. Thank you.

1 answer

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]

This discussion is preserved as it was. New answers, comments, and votes are closed.