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

How to save a custom inventory?

Asked by
if3q 6
4 years ago

I've been working on a working custom inventory which shows frames with images of hats in them, which you can click to equip the hat. I want to save the gui objects, and i want to save with a table (there are many hats), but it never works. Here is my code (datastore):

local dss = game:GetService("DataStoreService")
local ds = dss:GetDataStore("HatInv")


game.Players.PlayerAdded:Connect(function(p)
    local Data = ds:GetAsync("User-"..p.UserId)
    if Data ~= nil then
        for i, v in next(Data) do
            findObject = game.ReplicatedStorage.Hats:FindFirstChild(v):Clone()
            findObject.Parent = p:WaitForChild("PlayerGui").ScreenGui.Inventory.ScrollingFrame
        end
    else
        warn(Data)
    end
end)
game.Players.PlayerRemoving:Connect(function(p)
    local ToBeSaved = {}
    for i, v in pairs(p:WaitForChild("PlayerGui").ScreenGui.Inventory.ScrollingFrame:GetChildren())
    do
        table.insert(ToBeSaved, v.Name)

    end
    ds:SetAsync("User-"..p.UserId, ToBeSaved)
end)

Could anyone please help? Thanks in advance!

Answer this question