I know how to keep every tool i collected upon death but not how to keep CERTAIN tools COLLECTED upon death. Here is my script just in case:
function waitForSpawn(player)
for i=1,100 do
if player == nil or player.Parent == nil then return false end
if player.Character ~= nil and player.Character.Humanoid ~= nil and player.Character.Humanoid.Health ~= 0 then
return true
end
wait(1)
end
return false
end
function die(player, h)
if h.Health == 0 then
print("Keep Tools Script: ", player.Name, " has died.")
local items = {}
starterPackItems = game.StarterPack:getChildren()
for i=1,#starterPackItems do
if player.Backpack:findFirstChild(starterPackItems[i].Name) == nil then
table.insert(items, starterPackItems[i]:clone())
end
end
local backpackItems = player.Backpack:getChildren()
for i=1,#backpackItems do
table.insert(items, backpackItems[i]:clone())
end
if h ~= nil and h.Parent ~= nil then
local playerWep = h.Parent:getChildren()
for i=1,#playerWep do
local w = playerWep[i]
if w.className == "Tool" then
table.insert(items, w:clone())
end
end
end
waitForSpawn(player)
if player ~= nil then
local backpackItems = player.Backpack:getChildren()
for i=1,#backpackItems do
backpackItems[i]:remove()
end
for i=1,#items do
items[i].Parent = player.Backpack
end
end
end
end
function spawn(character)
local h = character:findFirstChild("Humanoid")
if h ~= nil then
local player = game.Players:playerFromCharacter(character)
if player ~= nil then
h.Changed:connect(function () die(player, h) end)
end
end
end
game.Workspace.ChildAdded:connect(spawn)
