Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Inventory items are not saving upon return?

Asked by 7 years ago

Hello!

I have a customized Backpack and Inventory for my game. When the player leaves the game and returns, the items inside the Backpack are there, but the items inside the Inventory are gone.

I assume I need to add additional lines to my DataStore script to save the Inventory items too? I added Line 4 and Line 21 to my DataStore, but its not quite working. Any advice? :)

Full DataStore script below for weapons/items:


--Setup the DataStore local ds = game:GetService("DataStoreService"):GetDataStore("Tools"); local tools = game.ServerStorage.ToolStorage; local Inventory = game.StarterGui.HUDSystem.MainInventory.InventoryBox; -- ADDED LINE --{[Check and Load]} game.Players.PlayerAdded:connect(function(plr) --Retrieve the potential data local data = ds:GetAsync(plr.UserId); --Check if it exists if data then --If it does, loop and clone respective tools. for _,v in next,data do local tool = tools:FindFirstChild(v); if tool then tool:Clone().Parent = plr.Backpack; tool:Clone().Parent = plr.Inventory; -- ADDED LINE end end end end) --{[Collect and Save]} game.Players.PlayerRemoving:connect(function(plr) --Make a table to hold all the data local toolList = {}; --Iterate through the backpack and fill the table in for _,v in next,plr.Backpack:GetChildren() do --Make sure it's actually a tool if v:IsA("Tool") or v:IsA("HopperBin") then toolList[#toolList+1] = v.Name; end end --Save the table ds:SetAsync(plr.UserId,toolList); end)
1
This has nothing to do with your datastore. Debug the custom inventory. cabbler 1942 — 7y
0
There doesn't appear to be anything wrong with my custom inventory? Is there a line of code I need to add to force a refresh/save? Never2Humble 90 — 7y

Answer this question