game.Players.PlayerAdded:Connect(function(player)
local c = player.Character or player.CharacterAdded:Wait()
c.Humanoid.Died:Connect(function()
btools = player.Backpack:GetChildren()
ctools = c:FindFirstChildOfClass("Tool")
end)
player.CharacterAdded:Connect(function()
for i, v in pairs(btools) do
local clone = game.Lighting:WaitForChild(v.Name):Clone()
clone.Parent = player.Backpack
btools = {}
end
if ctools then
local chartoolclone = game.Lighting:WaitForChild(ctools.Name):Clone()
chartoolclone.Parent = player.Backpack
ctools = nil
end
end)
end)
Btools and ctools are defined every time the player dies and are both set to nil after the tools get added. However, they appear to remain nil as this script only works properly once, and then the player spawns with an empty inventory. How can I make it so it retains the previous inventory before dying? (There are consumable items in the game, so it has to be the last state of the inventory).

1 comment
Consider using the StarterPack object inside of the Player class. Furthermore, I would recommend switching your storage method from Lighting to something like ServerStorage. https://scriptinghelpers.org/questions/86253/can-i-still-use-lighting-rather-than-replicatedstorage#79993. This post explains why. Overall this script is quite messy and I would simply rewrite it completely.