Trying to save a table of Boolvalues whenever one is changed

Hello people! I’m playing around with datastore2, trying to save a table with boolvalues’ properties when one of them gets changed. I’m quite new to data saving, so I’m kinda struggling with the solution, since data just doesn’t save at all. There are no errors in the output.

And yes, I know there are many other posts about a similar issue, but my brain just can’t seem to work anymore.

local SSS = game:GetService("ServerScriptService")
local DataStore = require(SSS.DataModule)

game.Players.PlayerAdded:Connect(function(Player)
    print(Player.Name)
    local ShopItems = DataStore("Items", Player)
    local ItemsFolder = Player:WaitForChild("ShopItems")
    
    local SavingItems = {}

    for i, v in pairs(ItemsFolder:GetChildren()) do
        if v:IsA("BoolValue") then
            table.insert(SavingItems,v.Value)
            print(SavingItems,v.Value)
        end
    end
    
    local function updateStat(updatedValue)
        SavingItems.Value = ShopItems:Get(updatedValue)
    end

    updateStat(false)
    ShopItems:OnUpdate(updateStat())
    
    for i,v in pairs(ItemsFolder:GetChildren()) do
        v:GetPropertyChangedSignal("Value"):Connect(function()
            ShopItems:Set(SavingItems.Value)
        end)
    end
end)

I’m grateful for any help.

Just use .Changed

Shouldn’t you be setting this to the SavingItems table, what even is SavingItems.Value??
Also before you set that you probably want to update the value of the bool in the `SavingItems’ table.

Also you might want to use a dictionary rather than a table

2 Likes

You could do something like this

local SavingItems = {}
local yourBool = --something


SavingItems[yourBool.Name] = yourBool.Value
yourBool.Changed:Connect(function(value))
    SavingItems[yourBool.Name] = value
end