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

DataStore will not work I need help!? QUICK

Asked by
Kenley67 -12
7 years ago
Edited 7 years ago

Please provide more explanation in your question. If you explain exactly what you are trying to accomplish, it will be much easier to answer your question correctly.
-- Here is the code! It gets to get stone save but the value doesnt work and it doesnt save it --         saves the cash tho
local dataStoreService = game:GetService("DataStoreService"):GetDataStore("KennyGumphaDaBest33333")
game.Players.ChildAdded:connect(function(plr)
    wait()
    local PlayerStats = Instance.new("Folder",plr)
    PlayerStats.Name = "PlayerStats"

    local Cash = Instance.new("NumberValue",PlayerStats)
    Cash.Name = "Cash"
    Cash.Value = 2500

    local stone = Instance.new("NumberValue",PlayerStats)
    stone.Name = "Stone"
    stone.Value = 50
    print"Got Stone Value"

    local key = 'id-'..plr.userId
    local getsaveddata = dataStoreService:GetAsync(key)
    if getsaveddata then
        Cash.Value = getsaveddata[1]
        stone.Value = getsaveddata[2]
        print"GotStoneSave"
    else
        local saving = {Cash.Value}
        print("Saving2 in progress")
        local saving2 = {stone.Value}
        print("Complete")
        dataStoreService:SetAsync(key,saving, saving2)
        print"Saved!"
    end

end)

        game.Players.PlayerRemoving:connect(function(plr)
     local key = 'id-'..plr.userId
     local save = {plr.PlayerStats.Cash.Value}
     local save2 = {plr.PlayerStats.Stone.Value}
     dataStoreService:SetAsync(key,save, save2)
    print("DataStore Activated")
end)

1 answer

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
7 years ago
Edited 7 years ago

You're attempting to save 'save2' as a third argument for the SetAsync function. The SetAsync function only takes in two arguments: The key and the value to save.

If you save it all to the same table, and reference it from the same table, you should be good.

Dictionaries are useful for organizing your DataStores.

local ds = game:GetService("DataStoreService"):GetDataStore("KennyGumphaDaBest33333")

game.Players.PlayerAdded:connect(function(plr)
    local key = 'id-'..plr.userId
    local PlayerStats = Instance.new("Folder",plr)
    PlayerStats.Name = "PlayerStats"

    local Cash = Instance.new("NumberValue",PlayerStats)
    Cash.Name = "Cash"
    Cash.Value = 2500

    local stone = Instance.new("NumberValue",PlayerStats)
    stone.Name = "Stone"
    stone.Value = 50

    local data = ds:GetAsync(key)
    if data then
        Cash.Value = data.Cash
        stone.Value = data.Stone
    else
        Cash.Value = 0
        stone.Value = 0
    end
end)

game.Players.PlayerRemoving:connect(function(plr)
     local key = 'id-'..plr.userId
     local save = {
        ["Cash"] = plr.PlayerStats.Cash.Value;
        ["Stone"] = plr.PlayerStats.Stone.Value;
    }
     ds:SetAsync(key,save)
end)
Ad

Answer this question