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

Stuck at SetAsync Loading works saving does not. Help please?

Asked by 6 years ago
Edited 6 years ago
Data = { -- Multiple StringValues -- }


if Data ~= nil and Data[1] and Data[1] ~= nil then

local DataStoreService = game:GetService("DataStoreService")

print("newsave1")

DataStoreService:GetDataStore("Datastore"):SetAsync(player.UserId, Data)

print("newsave2")

end

It prints newsave1 and stays at SetAsync not printing newsave2 i have no idea whats going on.

Please let me know if you know anything.

2 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

I am pretty sure the error is on line 4 so I will attempt to make another script that could probably help you understand how to use datastores and SetAsyncs, script in workspace, regular script!

game.Players.PlayerAdded:connect(function(p)
    local count = 1
    local plrKey = "Id-"..p.UserId
    locla ds = game:GetService("DataStoreService"):GetDataStore("Data") -- get data storage
    data = {} or nil -- use table.Insert for this stuff
    local savedValues = DataStore:GetAsync(key)
    for _, SaveData in pairs(data) do -- loops created
        local NewValue = Instance.new("StringValue", workspace) -- change to whatever suits you, remember to edit stuff then
        NewValue.Value = SaveData.Name
        if savedValues then
            NewValue.Value = savedValues[count]
            count = count + 1
        else
            local valuesToSave = {NewValue.Value}
        end
    end
end


game.Players.PlayerRemoving:connect(function(p) -- when players are about to go :O

    local key = "Id-"..p.userId

    --Save key: {Data}
    local valuesToSave = {data}
    DataStore:SetAsync(key, valuesToSave)

end)

This is a rough untested example of how I would do things to save strings and use SetAsync ^, Hope this helps

Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Theres no problem with line 04 because line 08 did print but line 12 did not print.

Could it be a problem when my script gets the children of a model and inserts the name and value into the table (data) whenever the player leaves?

0
Found the solution getting the children took too long so when it was done the player was already gone and it couldnt take the userid from it to save. rickje139 0 — 6y

Answer this question