[Solved] My Problem 4

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to be able to load player’s saved inventory into their backpack.

  2. What is the issue? Include screenshots / videos if possible!
    My saved inventory works perfectly as it appears and loads into my inventory gui and I also made sure to use print statements to make sure my inventory was saved and loaded. The only issue is that it is not being loaded properly into the player’s backpack, but displaying and updating properly in my inventory gui.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have already tried to parent the new item into the backpack so it can be added to the player’s backpack, but still will not load the item into it. I also made sure to fire the client to call on the update too and using it on another function where player added so I made sure whenever a player is added into the game, it instantly calls or use the loadInventory function. Any help or guidance will be greatly appreciated. Thanks in advance! - Garby

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

function IS.LoadInv(plr)
	local success, savedD= pcall(function()
		return DS:GetAsync(pl.UserId)
	end)

	if success and savedData then
		local inv = IS.backpack[player]
		local allItemsFolder = GamItm

		if not allItems then
			warn("folder not found in Server.")
			return
		end

		print(playr.Name .. " has " .. #savedD .. " itms to load.")

		for _, itemData in ipairs(savedData) do
			print("Loading item: " .. itemData.Name .. " with count: " .. itemData.Count)

			local itemCount = itemData.Count or 0
			if itemCount > 0 then
				local itemTemp = x:FindFirstChild(itemd.Name)
				if itemTem t
					for i = itemCount do
						print("Creating item: " .. item)

						-- Clone the item from AllItem
						local newItem = it:Clon(

						-- Ensure the item has a handle
						local handle = newItem:FindFirstChild("Handle")
						if not handle then
							warn("Handle not found for item: " .. itemData.Name)
							return
						end

						-- Set attributes if necessary
						newItem:SetAttribute("ItemTpe", newItem:GetAttribute() or "Default")
						newItem:SetAttribute("Droppble", newItem:GetAttribute() or false)

						-- Parent the new item to the player's Backpack
						new.Parent = player.Backpack
						print(item.Name .. " has been added to " .. player.Name .. "'s backpack.")
					end
				else
					warn("Item template not found for: " .. itemData.Name)
				
			else
		end

		
		print(play
	else
		warn("Failed to load inventory data for " .. player.Name .. ": " .. (savedData or "No saved data found."))
	end
end

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

2 Likes

When the player is added store the inventory as a variable. Then when the players character loads you need to put everything back into the backpack by using that previous variable

2 Likes

What do you mean store as a variable? I have a function for saving player inv already and already calling on IS.LoadInv when char is added. Only issue is items not appearing in player backpack when I went to check players.

More context about my inventory system:

I saved the players inventory once they disconnect by saving item name and item stack. And once player loads back in , IS.LoadInv runs and it uses GameItem, a folder in serverstorage that contains all my items and reference it and duplicate the items and item stack into players backpack.

My inventory system works as applied print statements to make sure data inventory is being saved after disconnect and being loaded once character is added. Only issue is that it is not appearing/loading into my player’s backpack. I hope this is enough info so you can help me out further or anyone.
I made sure to parent the item into player’s backpack which should had load it in but i dont understand why it wont load into the player’s backpack.

newItem.Parent = player.Backpack

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.