I'm trying to make an inventory, and i'm planning on adding more items, but I want it easier to do. I'm planning to add more items soon enough. I'm trying to make a table, so it reads the list of items values that is put somewhere, and copy those values to the player and still be able to save those values

ATTEMPT

local DSService = game:GetService('DataStoreService'):GetDataStore('HLLegendsInvServicetesta')
local ITEMService = game.ReplicatedStorage.CONFIG.Items
var = nil
game.Players.PlayerAdded:connect(function(plr)
	
	local inv = Instance.new('Model', plr)
	inv.Name = 'minventory'
	for _, v in pairs(ITEMService:GetChildren()) do
		if v:IsA('IntValue') then
			var = v:Clone()
			var.Parent = inv
			var.Name = v.Name
		end
	end
	
	local key = 'id'..plr.userId
	
	local savedvalues = DSService:GetAsync(key)
	
	if savedvalues then
		for _,v in pairs() do
			if v:IsA('IntValue') then
				 -- then I just gave up on this line.......
				-- it was supposed to save the values above, or set them to a save number....
			end
		end
	else
		local vts = {
			Tin.Value, 
			Iron.Value, 
			Tungsten.Value,  -- ignore these lists
			Meteorite.Value, 
			Lead.Value, 
			Copper.Value, 
			Granite.Value, 
			Steel.Value, 
			Gold.Value, 
			Diamond.Value
			}
		DSService:SetAsync(key, vts)
	end
end)

Read this if it helps
ITEMS LOCATION IF IT HELPS

game.Players.PlayerRemoving:connect(function(plr) -- Just if it helps doe
	local key = 'id'..plr.userId
	local items = plr.minventory
	local vts = {
		items.Tin.Value,
		items.Iron.Value,
		items.Tungsten.Value,
		items.Meteorite.Value,
		items.Lead.Value, -- ignore lists
		items.Copper.Value,
		items.Granite.Value,
		items.Steel.Value,
		items.Gold.Value,
		items.Diamond.Value
		}
	DSService:SetAsync(key, vts)
end)

I just kinda gave up on it since it's soo hard for my head. Sorry for a long question, i'm trying to make it as understandable as possible

2 comments

1

Please make your scripts shorter and more effective first please...

1

Don't forget to pre load the assets!