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

How do i save a table with datastore?

Asked by
if3q 6
4 years ago

Im trying to save a table with datastore but it never works. Please help!

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


game.Players.PlayerAdded:Connect(function(p)
    local Data = ds:GetAsync("User-"..p.UserId)
    local Data2 = table.unpack(Data)
    if Data2 ~= nil then
        for i, v in pairs(Data2) do
            local 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
        if v.ClassName == "Frame" then
            table.insert(ToBeSaved, v.Name)
        else

        end

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

Thanks in advance

0
You can't save objects, so you're going to have to serialize the objects and then put them in the table. y3_th 176 — 4y
0
You should have multible varibles for the table.unpack so It can go into multible values marine5575 359 — 4y
0
you also didn't pack it for unpack marine5575 359 — 4y

Answer this question