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

3 comments
You can't save objects, so you're going to have to serialize the objects and then put them in the table.
You should have multible varibles for the table.unpack so It can go into multible values
you also didn't pack it for unpack