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

Well, I'm trying to save tons of BoolValues for if a player owns this or that, but that doesn't matter, this is my script to save the players coins (which works):

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)


This is the code to save a testing bool value (does not work):

-- 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)
0
Try replacing 'true' and 'false' with 1 and 0. I'm not sure DataStores accept bools as values, they might not be automatically encoded like tables are. 1waffle1 2908 — 9y
0
Well, 1waffle1, I did that, updated my question, it still doesn't work. wackem 50 — 9y
0
What is not happening that is supposed to happen? Are there any errors? btw the standard for true and false is 1 and 0 not 0 and 1 1waffle1 2908 — 9y

Answer this question