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)
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.
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)]
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.