I have no idea of what happned but my all datastore just disappeared anyone know maybe what the problem?
local ToolFolder = game:GetService("ServerStorage"):FindFirstChild("SavedTools")
local DataStoreService = game:GetService("DataStoreService")
local SaveData = DataStoreService:GetDataStore("SieDffsagtfa32")
game.Players.PlayerAdded:Connect(function(Player)
local ToolData = SaveData:GetAsync(Player.UserId)
local BackPack = Player:WaitForChild("Backpack")
local StarterGear = Player:WaitForChild("StarterGear")
if ToolData ~= nil then
for i, v in pairs(ToolData) do
if ToolFolder:FindFirstChild(v) and BackPack:FindFirstChild(v) == nil and StarterGear:FindFirstChild(v) == nil then
ToolFolder[v]:Clone().Parent = BackPack
ToolFolder[v]:Clone().Parent = StarterGear
end
end
end
Player.CharacterRemoving:Connect(function(Character)
Character:WaitForChild("Humanoid"):UnequipTools()
end)
end)
game.Players.PlayerRemoving:Connect(function(Player)
local ToolTable = {}
for i, v in pairs(Player.Backpack:GetChildren()) do
table.insert(ToolTable, v.Name)
end
if ToolTable ~= nil then
SaveData:SetAsync(Player.UserId, ToolTable)
end
end)
I think you might have forgotten to load the tools. You’re not loading the tools unless it’s inside another script. Therefore, the backpack is most likely empty and saves an empty table.
I’ve tested it and also checked the datastore via a plugin and it seems to work perfectly fine. The only reason I could think the data disappearing is the fact that the player might leave faster than what the server can save. Try adding a quick script at the end.
Basically, there are a few ways to save backups. Some in-studio command bar. The other will run automatically.
For the automatic one, Save the data every few minutes on another datastore. If the value is 0 or nil then it won’t save. This is a good way to get data back from disappearing data sets.
lua````
local ToolFolder = game:GetService(“ServerStorage”):FindFirstChild(“SavedTools”)
local DataStoreService = game:GetService(“DataStoreService”)
local SaveData = DataStoreService:GetDataStore(“SieDffsagtfa32”)
game.Players.PlayerAdded:Connect(function(Player)
local ToolData = SaveData:GetAsync(Player.UserId)
local BackPack = Player:WaitForChild("Backpack")
local StarterGear = Player:WaitForChild("StarterGear")
if ToolData ~= nil then
for i, v in pairs(ToolData) do
if ToolFolder:FindFirstChild(v) and BackPack:FindFirstChild(v) == nil and StarterGear:FindFirstChild(v) == nil then
ToolFolder[v]:Clone().Parent = BackPack
ToolFolder[v]:Clone().Parent = StarterGear
end
end
end
Player.CharacterRemoving:Connect(function(Character)
Character:WaitForChild("Humanoid"):UnequipTools()
end)
end)
game.Players.PlayerRemoving:Connect(function(Player)
local ToolTable = {}
for i, v in pairs(Player.Backpack:GetChildren()) do
table.insert(ToolTable, v.Name)
end
if ToolTable ~= nil then
SaveData:SetAsync(Player.UserId, ToolTable)
game:BindToClose(function()
wait(2)
end)
end
I’m not sure if that BindToClose will work, you can try but it’s best to keep it outside.
Main - Script
local BackupHandler = task.spawn(function()
local Backup = game:GetService("DataStoreService"):GetDataStore("SieDffsagtfa32_Backup")
local SaveBackups = game.Players.PlayerAdded:Connect(function(Player)
local cooldown = 300 -- 5 minutes
while task.wait(cooldown) do if Player == nil then return end
local ToolTable = {}
for i, v in pairs(Player.Backpack:GetChildren()) do
table.insert(ToolTable, v.Name)
end
if ToolTable ~= nil or #ToolTable ~= 0 then
Backup:SetAsync(Player.UserId, ToolTable)
end
end
end)
end)
Full - Script
local BackupHandler = task.spawn(function()
local Backup = game:GetService("DataStoreService"):GetDataStore("SieDffsagtfa32_Backup")
local SaveBackups = game.Players.PlayerAdded:Connect(function(Player)
local cooldown = 5 -- 5 minutes
while task.wait(cooldown) do if Player == nil then return end
local ToolTable = {}
for i, v in pairs(Player.Backpack:GetChildren()) do
table.insert(ToolTable, v.Name)
end
if ToolTable ~= nil or #ToolTable ~= 0 then
Backup:SetAsync(Player.UserId, ToolTable)
end
end
end)
end)
local SaveDataHandler = task.spawn(function()
local ToolFolder = game:GetService("ServerStorage"):FindFirstChild("SavedTools")
local DataStoreService = game:GetService("DataStoreService")
local SaveData = DataStoreService:GetDataStore("SieDffsagtfa32")
game.Players.PlayerAdded:Connect(function(Player)
local ToolData = SaveData:GetAsync(Player.UserId)
local BackPack = Player:WaitForChild("Backpack")
local StarterGear = Player:WaitForChild("StarterGear")
if ToolData ~= nil then
for i, v in pairs(ToolData) do
if ToolFolder:FindFirstChild(v) and BackPack:FindFirstChild(v) == nil and StarterGear:FindFirstChild(v) == nil then
ToolFolder[v]:Clone().Parent = BackPack
ToolFolder[v]:Clone().Parent = StarterGear
end
end
end
Player.CharacterRemoving:Connect(function(Character)
Character:WaitForChild("Humanoid"):UnequipTools()
end)
end)
game.Players.PlayerRemoving:Connect(function(Player)
local ToolTable = {}
for i, v in pairs(Player.Backpack:GetChildren()) do
table.insert(ToolTable, v.Name)
end
if ToolTable ~= nil then
SaveData:SetAsync(Player.UserId, ToolTable)
end
end)
game:BindToClose(function()
task.wait(2)
end)
end)