I’ve been trying to work around my code with Auto-saving my tools whenever the player dies/resets. I have the code working for when the player leaves the game and rejoins, however I’ve looked for tutorials and tried on my own to keep the players tools upon death, and nothing seems to work. Yes, I have tried to adjust some tutorial’s code to fit with what I have, but I couldn’t get it to work. Here is the plain code with only the disconnection autosave:
local dataStoreService = game:GetService("DataStoreService")
local dataStore = dataStoreService:GetDataStore("BackpackSave")
local toolsFolder = game.ReplicatedStorage.Tools
local RunService = game:GetService("RunService")
toolsSave = {}
game.Players.PlayerAdded:Connect(function(player)
pcall(function()
local tool = dataStore:GetAsync("User-"..player.UserId)
if tool then
for i, v in pairs(tool) do
for i, tools in pairs(toolsFolder:GetChildren()) do
if v == tools.Name then
local toolclone1 = tools:Clone()
toolclone1.Parent = player.Backpack
local toolclone2 = tools:Clone()
toolclone2.Parent = player.StarterGear
end
end
end
end
end)
player.CharacterRemoving:Connect(function(character)
character:WaitForChild("Humanoid"):UnequipTools()
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
pcall(function()
for i, tool in pairs(player.Backpack:GetChildren()) do
if tool then
table.insert(toolsSave, tool.Name)
end
end
dataStore:SetAsync("User-"..player.UserId, toolsSave)
end)
end)
Any help is appreciated!