How could I search through a table for a certain thing?

So, I’m currently trying to make an inventory system. And whenever the player picks up an item it fires a remote event with the item name that they picked up. But I’m not sure how to use table.find() for it! I’ve also tried to use for i,v in pairs but that also didn’t work.
Here’s the script:

replicated_storage = game:GetService("ReplicatedStorage")
items = require(script.Parent.ItemData)

replicated_storage.itempickup.OnServerEvent:Connect(function(player, item)
	print(item)
	local newitem = table.find(items,item)
	if newitem then
		print(newitem)
	end
end)
1 Like

We need to know how the items table is structured like because table.find will go through the table to find the specified value while items[index] will go by the index.

1 Like

I’m actually figuring it out now, it’s just now im trying to weld. But thanks for helping!

1 Like

If this is still unsolved, using table.find() will return a number, which you can then use to locate the exact part you want. table[table.find(items, item)]

1 Like

i figured out a way to use for i,v in pairs

1 Like

Well first you have to get the name or of the item or object for example:

local tool = game:GetService("ServerStorage").pickaxe

And then you would have to get a table

local tbl = {"pickaxe","sword","shield"}

And then you can use table.find

local tool = game:GetService("ServerStorage").pickaxe
local tbl = {"pickaxe","sword","shield"}

if table.find(tbl,tool.Name) then --- arg 1 = The table.  arg 2 = the string
	-- code here
end

Im not sure if it helped or not but i was trying to explain how table.find worked.

2 Likes

I just did:

for i,v in pairs (items) do
		if i == item then
			print("found: ".. item)
			if v.itemtype == "boots" then

(items is a module
and item in the name of the item.)

1 Like

Yes, this does help a lot since now I know how it works :slight_smile:

1 Like