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

Why isn't this datastore saving my values??

Asked by 4 years ago

First time making my own DataStore, my values aren't saving for some reason??

local DataStore = game:GetService("DataStoreService")
local ToolSave = DataStore:GetDataStore("ToolSave")

game.Players.PlayerAdded:Connect(function(player)
    wait(3)
    --tool
    local Tools = player:WaitForChild("Tools")
    for i,Tool in pairs(Tools:GetChildren()) do
    --
    print(Tool.Value)
    local success, errormessage = pcall(function()
    local Key = player.UserId..Tool.Value
    local data = ToolSave:GetAsync(Key)
    if data then
        print("Player has data")
    elseif not data then
        print("Player has no data")
end
    end)
    if not success then
        warn("Error occurred while getting data err: "..errormessage)

        game.Players.PlayerRemoving:Connect(function(player)
            local success, errormessage = pcall(function()
                local Tools = player:WaitFOrChild("Tools")
                for i,tools in pairs(Tools:GetChildren()) do
                local Key = player.UserId.."-Tools"
                if success then
                    ToolSave:SetAsync(Key..tools.Value)
                    print("Saving tools!")
                elseif not success then
                    wait("Error occurred while saving tools: "..errormessage)
                end
                end
            end)
        end)
    end
    end
    end)

Answer this question