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

My DataStore won't work and save?

Asked by 5 years ago

The inventory is basically a folder inside ServerStorage The inventory has weopons inside it and inside the weopons has the IntValues inside them with numbers the Int Value is called IDNumber did i do this right or wrong? im trying to make it save

local DataStore = game:GetService("DataStoreService"):GetDataStore('ToolSave')
game.Players.PlayerAdded:Connect(function(plr)
    local savedStuff = DataStore:GetAsync(plr.userId)
    if savedStuff ~= nil then
        for i,v in pairs(savedStuff) do
            for a,k in pairs(game.ServerStorage.Inventory) do
                if k:WaitForChild('IDNumber').Value == v then
                    local weopon = k:Clone()
                    weopon.Parent = plr:WaitForChild('Backpack')

                end
            end
        end
    end
plr.CharacterRemoving:Connect(function()
plr.Character.Humanoid:UnequipTools()
end)
end)



game.Players.PlayerRemoving:Connect(function(plr)
    WeoponSaveTable = {}
    for i,v in pairs(plr.Backpack:GetChildren()) do
        table.insert(WeoponSaveTable,v:WaitForChild('IDNumber').Value)

    end
if WeoponSaveTable ~= nil then
    DataStore:SetAsync(plr.userId,WeoponSaveTable)
end


end)



Answer this question