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

DataStore is not saving Data how to fix that?

Asked by
Diltz_3 75
6 years ago

I don't know where's my problem.

I wanted to make when player is leaving and if he have items then all items will be saved like Table in Datastore. But I'm checking DataStore that's not saving.

Code: (Server Script)

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

game.Players.PlayerAdded:Connect(function(Player)
    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
    Key = Player.UserId
    local newTable = {}
    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)
            DSS:SetAsync(Key,newTable)
        end
    end
end)

Thank you if you help!

1 answer

Log in to vote
0
Answered by 6 years ago

Hey, how are you doing?

My guess would be that it'd be a timeout, or something of the likes.

    if findData then
        for i,v in pairs(findData:GetChildren()) do
            local findNames = v.Name
            table.insert(newTable,findNames)
            DSS:SetAsync(Key,newTable) ---
        end
    end

The line that I marked worries me since that it technically keeps saving every single time a new object was saved into the table.

Place that SetAsync outside of the for loop and see what happens.

    if findData then
        for i,v in pairs(findData:GetChildren()) do
            local findNames = v.Name
            table.insert(newTable,findNames)
        end
     DSS:SetAsync(Key,newTable)
    end

0
Sorry, but nothing UH OH ;( I'm not gettiing an error Diltz_3 75 — 6y
Ad

Answer this question