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

Why won't my data store save correctly?

Asked by 6 years ago

So I made a Data Store that saves both tools and money, but for some reason it doesn't work. The output doesn't show any errors so I got a dead end.

The Code:

local DSS = game:GetService("DataStoreService")
local MoneySave = DSS:GetDataStore("General", "Money")
local GearSave = DSS:GetDataStore("General", "Gear")

game.Players.PlayerAdded:Connect(function(player)
    local key = "player-".. player.UserId
    pcall(function()
        local money = MoneySave:GetAsync(key)
        local gear = GearSave:GetAsync(key)

        if money then
            player:WaitForChild("leaderstats"):WaitForChild("Money").Value = MoneySave[1]
        else
            local MoneyForSaving = {player:WaitForChild("leaderstats"):WaitForChild("Money").Value}
            MoneySave:GetAsync(key, MoneyForSaving)
        end

        if gear then
            for _,v in pairs(gear) do
                local gears = game:GetService("ReplicatedStorage"):FindFirstChild(v)
                if gears then
                    gears:Clone().Parent = player.Backpack
                    if not player.StarterGear:FindFirstChild(v) then
                        gears:Clone().Parent = player.StarterGear
                    end
                end
            end
        end
    end)
end)

game.Players.PlayerRemoving:Connect(function(player)
    local key = "player-".. player.UserId
    pcall(function()
        local MoneyToSave = {player:WaitForChild("leaderstats"):WaitForChild("Money").Value}
        local GearToSave = {}

        for _,v in pairs(player.Backpack) do
            table.insert(GearToSave, v.Name)
        end
    end)
end)

And please, tell me what I did wrong

0
hey, I made a script like this. I found a solution. Here's the answer: https://scriptinghelpers.org/ Vid_eo 126 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

You're getting the data store, but I don't see you setting it anywhere. Look into SetAsync and UpdateAsync.

Ad

Answer this question