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

Datastore is not saving saving changes in data despite no errors in output?

Asked by
Robb12 12
5 years ago
Edited 5 years ago

Hi I have been trying to code a data store and have run into an issue with the code I am trying to use

the script doesn't show any errors in the output bar, it just does not save any change in the data so at this point I am at a loss for what to do

local DSS = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local Server = game:GetService("ServerStorage")

local DS = DSS:GetDataStore("Eldaronservertest1238")

Players.PlayerAdded:Connect(function(Player)
    if Player ~= nil then 
        local UserId = Player.UserId
        local Key = "KeyScope:  "..UserId
        local MyData = DS:GetAsync(Key)
        local Folder = Instance.new("Folder")
        Folder.Name = tostring(UserId)
        local currency = Instance.new("NumberValue")
        Folder.Parent = Server
        currency.Name = "Bitcoin"
        currency.Parent = Folder

        local Success, Err = pcall(function()
            if MyData then
                currency.Value = MyData[1]
            else
                currency.Value = 500

            end
        end)

    if Success then print("Success")
    else
        warn("epic fail  "..Err)
    end     

    end
end)

Players.PlayerRemoving:Connect(function(Player)
    local UserId = Player.UserId
    local Key = "KeyScope:  "..UserId
    local Folder = Server[UserId]
    local Mydata = {Folder.Bitcoin.Value}

    DS:GetAsync(Key, Mydata)
    warn("Player data saved for:  "..UserId)

end)

1 answer

Log in to vote
0
Answered by
Robb12 12
5 years ago

Issue was I put GetAsync at the bottom of the script instead of SetAsync

0
... plox proof read your code before you post a question. BashGuy10 384 — 5y
Ad

Answer this question