#data store working in studio but not after publishing

1 messages · Page 1 of 1 (latest)

modern rune
#

I'm trying to make a data store system but for some reason it's behaving very weirdly, this is my code

check = function()
    if #game:GetService("Players"):GetPlayers() == 1 then
        return false
    else
        return true
    end
end

game.Players.PlayerRemoving:Connect(function(player)
    if check() then

        local invInfo = {}
        for _, tool in pairs(player.Backpack:GetChildren()) do
            print("WERE HERE")
            if tool:IsA("Tool") then
                if tool:GetAttribute("Type") then
                    local name = tool:GetAttribute("Type")
                    local quality = tool:GetAttribute("Quality")
                    local size = tool:GetAttribute("Size")

                    table.insert(invInfo, {quality, size, tool.Value.Value, name})
                end
            end
        end
        pcall(function()
            invStore:SetAsync(player.UserId, invInfo)
        end)
        local money = player.leaderstats.Money.Value
        pcall(function()
            moneyStore:SetAsync(player.UserId, money)
        end)
    end
    
end)


--
game:BindToClose(function()
    for _, player in pairs(game.Players:GetPlayers()) do
        local invInfo = {}
        for _, tool in pairs(player.Backpack:GetChildren()) do
            if tool:IsA("Tool") then
                if tool:GetAttribute("Type") then
                    local name = tool:GetAttribute("Type")
                    local quality = tool:GetAttribute("Quality")
                        local size = tool:GetAttribute("Size")

                    table.insert(invInfo, {quality, size, tool.Value.Value, name})
                end
            end
        end
        pcall(function()
            invStore:SetAsync(player.UserId, invInfo)
        end)

        local money = player.leaderstats.Money.Value
        pcall(function()
            moneyStore:SetAsync(player.UserId, money)
        end)
    end
    
end)```
#

there's no problem with loading the data, even when saving doesn't work it correctly loads the last saved data. the issue is that it works perfectly on studio, but once i publish the changes it stops saving, neither the cash nor the inventory is saved. I'd appreciate any insight (note: the task.wait(3) doesn't change anything, just thought I'd give it more time to load)