I’m new to tables so i dont know wat i am doing so wat i am trying to so is find the ItemID inside the table and get the info inside it but idk how
here is the script for my inventory i made :
local Player = game.Players.LocalPlayer
local itemDATA = require(game.ReplicatedStorage.Itemdata)
local InventoryHandler = require(script.Parent.ModuleScript)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local HttpService = game:GetService("HttpService")
local inventoryGUI = script.Parent
local Frame = inventoryGUI:WaitForChild("Items")
local Template = inventoryGUI.Template:WaitForChild("Template")
local DataFolder = ReplicatedStorage.ReplicatedData:WaitForChild(Player.UserId)
DataFolder.Inventory.Changed:Connect(function(encodedData)
local dataTable = HttpService:JSONDecode(encodedData)
for itemName, amount in pairs(dataTable) do
local label = Frame:FindFirstChild(itemName)
print(table.find(itemDATA.data))
if (not label) then
label = Template:Clone()
label.Name = itemName
label.Parent = Frame
label.Visible = true
end
end
end)
here is the code i made :
print(table.find(itemDATA.data))
here is the itemData :
local Items = {}
Items.data = {
{
Name = "Hat";
ImageID = 1409499909;
Cost = 100;
Value = 10;
Tier = "Commen";
ItemID = 1
};
{
Name = "Pants";
ImageID = 128302713;
Cost = 30;
Value = 100;
Tier = "Commen";
ItemID = 2
};
{
Name = "Shirt";
ImageID = 495262405;
Cost = 330;
Value = 1000;
Tier = "Commen";
ItemID = 3
};
{
Name = "Glasses";
ImageID = 1439396148;
Cost = 2000;
Value = 1000;
Tier = "Uncommen";
ItemID = 4
};
{
Name = "Chain";
ImageID = 1027719587;
Cost = 1233;
Value = 4623;
Tier = "Uncommen";
ItemID = 5
};
}
return Items
the data is saved in DataStore2 here is the saved data :
When i make modules to store information like this I usually have a function at the very bottom for finding the information via ID or Name
Heres of an Example: Of a function i would add at the end of your items module
Items.Get_Item_FromID(ID)
function Items.Get_Items_FromID(ID)
for Items,Item in pairs(Items) do --// Looping thru module
if type(Item)== "table" and Item.ItemID == ID then --// Checking if Item is a table and if ID_Parameter == ID
return Item --// Returns Item if found
end
end
end
end
What I’m going to recommend would require your to call your items module (preferable outside of the function like your other variables)
for itemName, amount in pairs(dataTable) do
local ItemInfo = Items.Get_Item_FromID(itemName) --// You can use my example if u like or make your own up to you
print(teminfo)
--// Label creation here
end
No errors? can you send what you copied. Actually nvm.
function Items.Get_Items_FromID(ID)
for Items,Item in pairs(Items) do --// Looping thru module
if type(Item)== "table" and Item.ItemID == ID then --// Checking if Item is a table and if ID_Parameter == ID
return Item --// Returns Item if found
end
end
end
function Items.Get_Items_FromID(ID)
print("Checking For ItemID")
for Items,Item in pairs(Items) do --// Looping thru module
print(Items,Item)
if type(Item)== "table" and Item.ItemID == ID then --// Checking if Item is a table and if ID_Parameter == ID
print(Item)
return Item --// Returns Item if found
end
end
end
Did you change in pairs(Items) to be the name of your module
for Items,Item in pairs(Name of your module) do --// Looping thru module
local Player = game.Players.LocalPlayer
local itemDATA = require(game.ReplicatedStorage.Itemdata)
local InventoryHandler = require(script.Parent.ModuleScript)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local HttpService = game:GetService("HttpService")
local inventoryGUI = script.Parent
local Frame = inventoryGUI:WaitForChild("Items")
local Template = inventoryGUI.Template:WaitForChild("Template")
local DataFolder = ReplicatedStorage.ReplicatedData:WaitForChild(Player.UserId)
DataFolder.Inventory.Changed:Connect(function(encodedData)
local dataTable = HttpService:JSONDecode(encodedData)
for itemName, amount in pairs(dataTable) do
local ItemInfo = itemDATA.Get_Item_FromID(itemName) --// You can use my example if u like or make your own up to you
print(ItemInfo)
--// Label creation here
end
--[[for itemName, amount in pairs(dataTable) do
local label = Frame:FindFirstChild(itemName)
print(table.find(itemDATA.data))
if (not label) then
label = Template:Clone()
label.Name = itemName
label.Parent = Frame
label.Visible = true
end
end]]--
end)
module script :
local Items = {}
Items.data = {
{
Name = "Hat";
ImageID = 1409499909;
Cost = 100;
Value = 10;
Tier = "Commen";
ItemID = 1
};
{
Name = "Pants";
ImageID = 128302713;
Cost = 30;
Value = 100;
Tier = "Commen";
ItemID = 2
};
{
Name = "Shirt";
ImageID = 495262405;
Cost = 330;
Value = 1000;
Tier = "Commen";
ItemID = 3
};
{
Name = "Glasses";
ImageID = 1439396148;
Cost = 2000;
Value = 1000;
Tier = "Uncommen";
ItemID = 4
};
{
Name = "Chain";
ImageID = 1027719587;
Cost = 1233;
Value = 4623;
Tier = "Uncommen";
ItemID = 5
};
}
function Items.Get_Items_FromID(ID)
print("Checking For ItemID")
for Items,Item in pairs(Items) do --// Looping thru module
print(Items,Item)
if type(Item)== "table" and Item.ItemID == ID then --// Checking if Item is a table and if ID_Parameter == ID
print(Item)
return Item --// Returns Item if found
end
end
end
return Items