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

Datastore is not saving a table how to fix that?

Asked by
Diltz_3 75
5 years ago
Edited 5 years ago

I'm tried to make inventory save and when player leaving creating new table with items. But this is not saving

I'm not getting an error

Code: (Server Script)

local DSS = game:GetService("DataStoreService"):GetDataStore("NewDStestq312")
local RS = game:GetService("ReplicatedStorage")

game.Players.PlayerAdded:Connect(function(Player)
    local Key
    Key = Player.UserId
    local Folder = Instance.new("Folder",RS)
    Folder.Name = Player.Name.."-Inventory.UID-"..Player.UserId
    local getData = DSS:GetAsync(Player.UserId)
    if getData then
        print("Test")
    end
end)

game.Players.PlayerRemoving:Connect(function(Player)
    local Key
    local newTable = {}
    Key = Player.UserId
    local findData = RS:FindFirstChild(Player.Name.."-Inventory.UID-"..Player.UserId)
    if findData then
       for i,v in pairs(findData:GetChildren()) do
           local findNames = v.Name
           table.insert(newTable,findNames)
       end
       wait()
       DSS:SetAsync(Key,newTable)
    end
end)
0
The key needs to be a string. Set key to something like Key = "Player_"..Player.UserId and the parent argument to Instance.new is deprecated and is known to slow down game performance. Unless your game is a lag simulator, do not use it. User#19524 175 — 5y
0
I'm not doing a simulator..................................................... Diltz_3 75 — 5y

Answer this question