How to Stop the Backpack from Erasing

I wanted to incorporate a feature in my game where your inventory does not clear when you die, but I don’t know how to create this.

I don’t want to create an item saving system, I just want the backpack to not be destroyed when you die.

An example:

2 Likes

I’m not sure this is possible without item saving. You could possibly check if the humanoid dies and set a value as the tools name and clone it into the backpack when they respawn using a characteradded function.

I mean saving their whole backpack, not just an item.

You could simply do something like this:

local ToolsSaved = {};
local LocalPlayer = game["Players"]["PlrName"]

LocalPlayer["Character"]["Humanoid"]["Died"]:Connect(function()
  for I, V in pairs(LocalPlayer["Backpack"]:GetChildren()) do 
    if V:IsA("Tool") then
      table.insert(ToolsSaved, V["Name"])
     end
  end 
end)

LocalPlayer["CharacterAdded"]:Connect(function()
 for I, V in pairs(ToolsSaved) do 
  if ServerStorage:FindFirstChild(V) then 
    ServerStorage:FindFirstChild(V):Clone()["Parent"] = LocalPlayer["Backpack"]
   end
 end
ToolsSaved = {}
end)
1 Like

This has worked! Thank you.

I created something similar since I had my own things in play:

local SS = game:GetService("ServerStorage")
local Players = game:GetService("Players")

local itemTools = SS.ItemTools

Players.PlayerAdded:Connect(function(player)
	local character
	
	local savedItems = {}
	local con
	
	local function Reconnect()
		character = player.Character or player.CharacterAdded:Wait()
		con = character:WaitForChild("Humanoid").Died:Connect(function()
			for _, item in ipairs(player.Backpack:GetChildren()) do
				if item:IsA("Tool") then
					table.insert(savedItems, item.Name)
				end
			end
		end)
	end
	
	Reconnect()
	
	player.CharacterAdded:Connect(function()
		for _, item in ipairs(savedItems) do
			local newItem = itemTools[item]:Clone()
			newItem.Parent = player:WaitForChild("Backpack")
		end
		savedItems = {}
		
		con:Disconnect()
		Reconnect()
	end)
end)
1 Like
local Game = game
local Players = Game:GetService("Players")

local function OnPlayerAdded(Player)
	local function OnCharacterAdded(Character)
		local Backpack = Player:FindFirstChildOfClass("Backpack") or Player:WaitForChild("Backpack")
		local Humanoid = Player:FindFirstChildOfClass("Humanoid") or Player:WaitForChild("Humanoid")
		
		local function OnHumanoidDied()
			Humanoid:UnequipTools()
			for _, Tool in ipairs(Backpack:GetChildren()) do
				Tool.Parent = Player
			end
		end
		
		Humanoid.Died:Connect(OnHumanoidDied)
		for _, Tool in ipairs(Player:GetChildren()) do
			if not (Tool:IsA("Tool")) then continue end
			Tool.Parent = Backpack
		end
	end
	
	Player.CharacterAdded:Connect(OnCharacterAdded)
end

Players.PlayerAdded:Connect(OnPlayerAdded)
2 Likes

Thank your for the script but it’s a bit lackluster and unneeded, and your preferred way of variable labeling is weird to me.

Hey @Forummer why do you make variables for services that already have simple “variable like” names, such as local Game = game

I shared it for others who need a more generic script, the one you shared seems to be heavily dependent on your game’s system.

1 Like