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

DataStore is not working?

Asked by
wackem 50
8 years ago

My entire leaderboard works, with saving, but when I get to this:

-- Note: 0 = true, 1 = false

DataStore = game:GetService("DataStoreService"):GetDataStore("OwnsTest")
local t = script.Parent.Frame.Owns
local p = t.Parent.Parent.Parent.Parent.Parent.Parent
local b = script.Parent.Frame.TextButton

b.MouseButton1Click:connect(function()
    local st = p.AnimsChar.OwnsTest
    if st.Value == 1 then
        st.Value = 0
    elseif st.Value == 0 then
        t.Text = "True"
    end
end)

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

game.Players.PlayerRemoving:connect(function(plr)
    local owns = plr.AnimsChar.OwnsTest.Value
    local save = "plr-"..plr.userId
    DataStore:SetAsync(save, owns)
end)

It suddenly doesn't work

This is my leaderboard:

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

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 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 = 1
end)

game.Players.PlayerRemoving:connect(function(plr)
    local val = plr.leaderstats.Coins.Value
    local save = "plr-"..plr.userId
    DataStore:SetAsync(save,val)
end)
0
Accidentally moderated this, sorry. thought it would report it to staff to fix. HungryJaffer 1246 — 8y

Answer this question