#my datastore is not Saving

1 messages · Page 1 of 1 (latest)

proper ore
#

Getting dataStore:-

local shopUi = plr.PlayerGui:WaitForChild("shopGUI")
    local shop = shopUi.Shop
    local folder = shop.butttons
    local s,e = pcall(function()
        return ownedStore:GetAsync(plr.UserId)
    end)
    if s then
        for i,v in pairs(folder:GetChildren()) do
            if v.Name == ownedStore:GetAsync(plr.UserId) then
                v.owned.Value = true
            end
        end
    else
        warn(e)
    end
end)

Saving the dataStore:-

game.ReplicatedStorage.BuyEvent.OnServerEvent:Connect(function(plr,pizza)
    local shop = plr.PlayerGui.shopGUI.Shop
    local leaderstats = plr.leaderstats
    local coins = leaderstats.Coins
    local inv = plr.Inventory
    local multi = inv.Multiplier
    local price = pizza:GetAttribute("price")
    local multiadded = pizza:GetAttribute("multiplier")
    local owned = pizza.owned
    owned.Value = true
    coins.Value -= price
    multi.Value = multiadded
    multiStore:SetAsync(plr.UserId,multi.Value)
    local s,v = pcall(function()
        return ownedStore:GetAsync(plr.UserId)
    end)
    if not s then
        ownedStore:SetAsync(plr.UserId,pizza.Name)
    else
        ownedStore:IncrementAsync(pizza.owned.Value)
    end
end)
proper kestrel
#

to save data it's better to use this

#
    saveData(plr)
end)

game:BindToClose(function()
    for _, plr in ipairs(game.Players:GetPlayers()) do
        task.spawn(saveData, plr)
    end
end)
#

where save data is a table with all values to be saved

#

with calling data:SetAsync()