i was troubleshooting my data store script and realized that every time the player leaves instead of the data store updating the saved data it adds to it instead
in this picture you can only see a small part of the output, it goes on for ever, each part is one save, if you know why its doing so please tell me, i’m sorry for the bad explanation
local DataStore = game:GetService("DataStoreService"):GetDataStore("PlayerOutfits1")
local DataStore1 = game:GetService("DataStoreService"):GetDataStore("PlayerOutfits2")
local DataStore2 = game:GetService("DataStoreService"):GetDataStore("PlayerOutfits3")
function OnPlayerAdded(player)
player.CharacterAdded:Wait()
wait(0.1)
local Outfits = nil
local success, err = pcall(function()
Outfits = DataStore:GetAsync(player.UserId)
end)
if Outfits then
for i, DataS in pairs(Outfits) do
local AvatarOutfits = player.Backpack.AvatarOutfits
if AvatarOutfits then
for i, v in pairs(AvatarOutfits:GetChildren()) do
if v:IsA("Model") then
print(v.Name.." Outfit Number")
local Description = v.Humanoid:GetAppliedDescription()
if Outfits["hat"..v.Name] ~= nil then
Description.HatAccessory = Outfits["hat"..v.Name]
print(Outfits["hat"..v.Name])
end
if Outfits["back"..v.Name] ~= nil then
Description.BackAccessory = Outfits["back"..v.Name]
print(Outfits["back"..v.Name])
end
if Outfits["face"..v.Name] ~= nil then
Description.FaceAccessory = Outfits["face"..v.Name]
print(Outfits["face"..v.Name])
end
if Outfits["front"..v.Name] ~= nil then
Description.FrontAccessory = Outfits["front"..v.Name]
print(Outfits["front"..v.Name])
end
if Outfits["hair"..v.Name] ~= nil then
Description.HairAccessory = Outfits["hair"..v.Name]
print(Outfits["hair"..v.Name])
end
if Outfits["neck"..v.Name] ~= nil then
Description.NeckAccessory = Outfits["neck"..v.Name]
print(Outfits["neck"..v.Name])
end
if Outfits["shoulder"..v.Name] ~= nil then
Description.ShouldersAccessory = Outfits["shoulder"..v.Name]
print(Outfits["shoulder"..v.Name])
end
if Outfits["waist"..v.Name] ~= nil then
Description.WaistAccessory = Outfits["waist"..v.Name]
print(Outfits["waist"..v.Name])
end
if Outfits["HeadFace"..v.Name] ~= nil then
Description.Face = Outfits["HeadFace"..v.Name]
print(Outfits["HeadFace"..v.Name])
end
if Outfits["Shirt"..v.Name] ~= nil then
Description.Shirt = Outfits["Shirt"..v.Name]
print(Outfits["Shirt"..v.Name])
end
if Outfits["Pants"..v.Name] ~= nil then
Description.Pants = Outfits["Pants"..v.Name]
print(Outfits["Pants"..v.Name])
end
v.Humanoid:ApplyDescription(Description)
end
end
end
end
end
if success then
print("Finished Loading The DataStore")
end
if not success then
print("There was an error while getting data of player " .. player.Name)
warn(err)
end
local Outfits2 = nil
local success, err = pcall(function()
Outfits2 = DataStore2:GetAsync(player.UserId)
end)
if Outfits2 then
for i, v in pairs(Outfits2) do
local AvatarOutfits = player.Backpack.AvatarOutfits
if AvatarOutfits then
for i, v in pairs(AvatarOutfits:GetChildren()) do
if v:IsA("Folder") then
if v.Name == "Values" then
for i,x in pairs(v:GetChildren()) do
for i,Values in pairs(x:GetChildren()) do
Values.Value = Outfits2[Values.Name.."Value"..x.Name]
print(Outfits2[Values.Name.."Value"..x.Name])
end
end
else if v.Name == "DeleteButtons" then
for i,x in pairs(v:GetChildren()) do
for i,values in pairs(x:GetChildren()) do
for i,allOutfitValues in pairs(Outfits2) do
local newButton = script.DeleteButton:Clone()
newButton.Parent = x
if allOutfitValues:find("Hats") then
newButton.Name = "Hats"
newButton.AccesorryID.Value = Outfits2["DeleteButtonHats"..x.Name]
elseif allOutfitValues:find("Back") then
newButton.Name = "Back"
newButton.AccesorryID.Value = Outfits2["DeleteButtonBack"..x.Name]
elseif allOutfitValues:find("Face") then
newButton.Name = "Face"
newButton.AccesorryID.Value = Outfits2["DeleteButtonFace"..x.Name]
elseif allOutfitValues:find("Front") then
newButton.Name = "Front"
newButton.AccesorryID.Value = Outfits2["DeleteButtonFront"..x.Name]
elseif allOutfitValues:find("Hair") then
newButton.Name = "Hair"
newButton.AccesorryID.Value = Outfits2["DeleteButtonHair"..x.Name]
elseif allOutfitValues:find("Neck") then
newButton.Name = "Neck"
newButton.AccesorryID.Value = Outfits2["DeleteButtonNeck"..x.Name]
elseif allOutfitValues:find("Shoulder") then
newButton.Name = "Shoulder"
newButton.AccesorryID.Value = Outfits2["DeleteButtonShoulder"..x.Name]
elseif allOutfitValues:find("Waist") then
newButton.Name = "Waist"
newButton.AccesorryID.Value = Outfits2["DeleteButtonWaist"..x.Name]
end
newButton.Img.Image = "https://www.roblox.com/asset-thumbnail/image?assetId="..newButton.AccesorryID.Value.."&width=420&height=420&format=png"
end
end
end
end
end
end
end
end
end
end
if success then
print("Finished Loading The DataStore")
end
if not success then
print("There was an error while getting data of player " .. player.Name)
warn(err)
end
end
function OnPlayerRemoving(player)
local Outfits = {}
local Outfits2 = {}
local AvatarOutfits = player.Backpack.AvatarOutfits
if AvatarOutfits then
for i, v in pairs(AvatarOutfits:GetChildren()) do
if v:IsA("Model") then
local Description = v.Humanoid:GetAppliedDescription()
if Description.HatAccessory ~= "" then
Outfits["hat"..v.Name] = Description.HatAccessory
print("Saved")
end
if Description.BackAccessory ~= "" then
Outfits["back"..v.Name] = Description.BackAccessory
print("Saved")
end
if Description.FaceAccessory ~= "" then
Outfits["face"..v.Name] = Description.FaceAccessory
print("Saved")
end
if Description.FrontAccessory ~= "" then
Outfits["front"..v.Name] = Description.FrontAccessory
print("Saved")
end
if Description.HairAccessory ~= "" then
Outfits["hair"..v.Name] = Description.HairAccessory
print("Saved")
end
if Description.NeckAccessory ~= "" then
Outfits["neck"..v.Name] = Description.NeckAccessory
print("Saved")
end
if Description.ShouldersAccessory ~= "" then
Outfits["shoulder"..v.Name] = Description.ShouldersAccessory
print("Saved")
end
if Description.WaistAccessory ~= "" then
Outfits["waist"..v.Name] = Description.WaistAccessory
print("Saved")
end
if Description.Face ~= 0 then
Outfits["HeadFace"..v.Name] = Description.Face
print("Saved")
end
if Description.Shirt ~= 0 then
Outfits["Shirt"..v.Name] = Description.Shirt
print("Saved")
end
if Description.Pants ~= 0 then
Outfits["Pants"..v.Name] = Description.Pants
print("Saved")
end
end
if v:IsA("Folder") then
if v.Name == "Values" then
for i,x in pairs(v:GetChildren()) do
for i,Values in pairs(x:GetChildren()) do
if Values.Value ~= 0 then
Outfits2[Values.Name.."Value"..x.Name] = Values.Value
print("Saved Values Folder")
print(Values.Value)
end
end
end
else if v.Name == "DeleteButtons" then
for i,x in pairs(v:GetChildren()) do
for i,values in pairs(x:GetChildren()) do
Outfits2["DeleteButton"..values.Name..x.Name] = values.AccesorryID.Value
print("Saved Delete Buttons")
print(values.AccesorryID.Value)
end
end
end
end
end
end
local success, err = pcall(function()
DataStore:RemoveAsync(player.UserId)
DataStore:SetAsync(player.UserId, Outfits)
DataStore2:RemoveAsync(player.UserId)
DataStore2:SetAsync(player.UserId, Outfits2)
print("Save Has Been Asynced")
end)
if not success then
print("There was an error while saving data of player " .. player.Name)
warn(err)
end
end
end
game.Players.PlayerAdded:Connect(OnPlayerAdded)
game.Players.PlayerRemoving:Connect(OnPlayerRemoving)
i know my script is messy but i will get to making it nicer once it works