Why is this data save script now saving the tools in a player's backpack and startergear?
local Data = game:GetService("DataStoreService"):GetDataStore("Inventory")
game.Players.PlayerAdded:Connect(function(player)
local SavedStuff
local suc, err = pcall(function()
SavedStuff = Data:GetAsync(player.UserId)
end)
if SavedStuff == nil then
for i,v in pairs(SavedStuff)do
if game.ServerStorage.Tools:FindFirstChild(v)~= nil then
game.ServerStorage.Tools:FindFirstChild(v):Clone().Parent = player.StarterGear
game.ServerStorage.Tools:FindFirstChild(v):Clone().Parent = player.Backpack
end
end
end
player.CharacterRemoving:Connect(function()
player.Character.Humanoid:UnequipTools()
end)
end)
game.Players.PlayerRemoving:Connect(function(plr)
local Table = {}
for i,v in pairs(plr.Backpack:GetChildren())do
table.insert(Table,v.Name)
end
if Table ~= nil then
pcall(function()
Data:SetAsync(plr.UserId,Table)
end)
end
end)
game:BindToClose(function(plr)
for _, plr in pairs(game:GetService("Players"):GetPlayers()) do
coroutine.wrap(function()
local Table = {}
for i,v in pairs(plr.Backpack:GetChildren())do
table.insert(Table,v.Name)
end
if Table ~= nil then
pcall(function()
Data:SetAsync(plr.UserId,Table)
end)
end
end)()
end
end)
Re-edited by JesseSong!