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

DataStore2 and DataStore not saving a set table of bool values?

Asked by
Donut792 216 Moderation Voter
5 years ago

so i have tried both DataStore and DataStore2 to save a list of boolvalues for me and its not saving when it changes but in the server log it says that it does, but it doesnt i do have a DataStore that saves another set of boolvalues and it works just fine even being a regular DataStore

here is the script i got to save them

local DS2 = require(1936396537)

game.Players.PlayerAdded:Connect(function(plr)
    local speedData = DS2('Speed', plr)--Get the speed datastore
    local healthData = DS2('Health', plr)--Get the health datastore
    --Speed
    local Speed = Instance.new("Folder")
    Speed.Name = "Speed"
    Speed.Parent = plr
    local Five = Instance.new("BoolValue")
    Five.Name = "Five"
    Five.Parent = Speed
    local Ten = Instance.new("BoolValue")
    Ten.Name = "Ten"
    Ten.Parent = Speed
    local Fifteen = Instance.new("BoolValue")
    Fifteen.Name = "Fifteen"
    Fifteen.Parent = Speed
    local Twenty = Instance.new("BoolValue")
    Twenty.Name = "Twenty"
    Twenty.Parent = Speed
    for i,v in pairs (Speed:GetChildren()) do
        v.Changed:connect(function() 
            local Saving = {
                ["Five"] = (plr.Speed).Five.Value;
                ["Ten"] = (plr.Speed).Ten.Value;
                ["Fifteen"] = (plr.Speed).Fifteen.Value;
                ["Twenty"] = (plr.Speed).Twenty.Value;
            }
            speedData:Set(Saving)
            print('Saved '..plr.Name..'s Speed Data')
        end)
    end
    print("Gave "..plr.Name.." Speed Data")
    local SavedItems = speedData:Get(nil)
    if SavedItems then
        Five.Value = SavedItems.Five or false
        Ten.Value = SavedItems.Ten or false
        Fifteen.Value = SavedItems.Fifteen or false
        Twenty.Value = SavedItems.Twenty or false
        print(plr.Name.." had Speed data")
    else
        Five.Value = false
        Ten.Value = false
        Fifteen.Value = false
        Twenty.Value = false
        print(plr.Name.." didn't have Speed data")
    end
    --MaxHealth
    local MaxHealth = Instance.new("Folder")
    MaxHealth.Name = "MaxHealth"
    MaxHealth.Parent = plr
    local First = Instance.new("BoolValue")
    First.Name = "First"
    First.Parent = MaxHealth
    local Second = Instance.new("BoolValue")
    Second.Name = "Second"
    Second.Parent = MaxHealth
    local Third = Instance.new("BoolValue")
    Third.Name = "Third"
    Third.Parent = MaxHealth
    local Fourth = Instance.new("BoolValue")
    Fourth.Name = "Fourth"
    Fourth.Parent = MaxHealth
    local Fifth = Instance.new("BoolValue")
    Fifth.Name = "Fifth"
    Fifth.Parent = MaxHealth
    for i,v in pairs (MaxHealth:GetChildren()) do
        v.Changed:connect(function()
            local Saving = {
                ["First"] = (plr.MaxHealth).First.Value;
                ["Second"] = (plr.MaxHealth).Second.Value;
                ["Third"] = (plr.MaxHealth).Third.Value;
                ["Fourth"] = (plr.MaxHealth).Fourth.Value;
                ["Fifth"] = (plr.MaxHealth).Fourth.Value;
            }
            healthData:Set(Saving)
            print('Saved '..plr.Name's MaxHealth Data.')
        end)
    end
    print("Gave "..plr.Name.." MaxHealth Data")
    SavedItems = healthData:Get(nil)
    if SavedItems then
        First.Value = SavedItems.First or false
        Second.Value = SavedItems.Second or false
        Third.Value = SavedItems.Third or false
        Fourth.Value = SavedItems.Fourth or false
        Fifth.Value = SavedItems.Fifth or false
        print(plr.Name.." had MaxHealth data")
    else
        First.Value = false
        Second.Value = false
        Third.Value = false
        Fourth.Value = false
        Fifth.Value = false
        print(plr.Name.." didn't have MaxHealth data")
    end
end)

when the values change the server does print Saved MaxHealth Data but when a player rejoins the value is back at false

0
Your table will take time for the datastores to SetAsync PenguinDevs 45 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

Yo, I think that I might see the solution epescially for your type of tables that are very large and may take a little longer to SetAsync, you should add in a :BindToClose and then add in a wait, so it gives your Datastores to Setasync I used to have the same problem as you, this is what helped me from the past

game:BindToClose(function()
    if runservice:IsStudio() then
        --wait(2) --Turn on/off wether you wanna enable it on studio
        return
    else
        wait(2)
    end
end)

Feel free to paste it on your script(Also it's highly recommended that you dont delete the comments on line 3, because your studio won't respond if you use a wait for bind to close on studio

0
alright thanks man i didnt really think about using bindtoclose on datastore2 Donut792 216 — 5y
0
DataStore2 uses BindToClose already when saving data. Kampfkarren 215 — 5y
Ad

Answer this question