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

DataStore not working?

Asked by
wackem 50
9 years ago

Alright, so I just edited my leaderboard to save something I've been trying to for a week or so, but now the previously saving coins, don't save, but "OwnsTest" does.

Code:

DataStore = game:GetService("DataStoreService"):GetDataStore("Values")
Bools = game:GetService("DataStoreService"):GetDataStore("Bools")

game.Players.PlayerAdded:connect(function(plr)
    local val = 0
    local save = "plr-"..plr.userId
    local savedVals = DataStore:GetAsync(save)
    if savedVals then
        val = savedVals
    else 
        val = 0
        DataStore:SetAsync(save, val)
    end

    local ownsTst = 0
    local savT = "plr-"..plr.userId.."B"
    local savTst = Bools:GetAsync(savT)
    if savTst then
        ownsTst = savTst
    else
        ownsTst = 0
        Bools:SetAsync(savT, ownsTst)
    end

    local stat = Instance.new("IntValue", plr)
    stat.Name = "leaderstats"   

    local cred = Instance.new("IntValue", stat)
    cred.Value = val
    cred.Name = "Coins"

    local folder = Instance.new("Folder", plr)
    folder.Name = "AnimsChar"

    -- BoolVals--
    local st = Instance.new("IntValue", folder)
    st.Name = "OwnsTest"
    st.Value = ownsTst
end)

game.Players.PlayerRemoving:connect(function(plr)
    local val = plr.leaderstats.Coins.Value
    local save = "plr-"..plr.userId
    DataStore:SetAsync(save,val)
end)

game.Players.PlayerRemoving:connect(function(plr)
    for _,bool in pairs(plr.AnimsChar:GetChildren()) do
    local save = "plr-"..plr.userId.."B"
    Bools:SetAsync(save, bool.Value)
end
end)

Answer this question