Ok so this is a really important script that I need for my game and I really want someone to help me with this.
This script basically saves your tools once you die and puts them in your inventory when you respawn, simple, but it only gets the tools from the players Backpack and not the character. So if I was holding a tool and died I wouldn't get it back. I've tried many things to fix this, but nothing worked. One time it worked when I used [ player.Character:getChildren() ] and cloned it when the player died, but then I realized that it also clones the player's legs and everything.
Also don't say "put your tools in StarterPack" because that is not what I need.
( Script is located in ServerScriptService as a server script )
function waitForSpawn(player)
for i=1,100 do
if player == 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
---- Need Fixing Here v
function die(player, h)
if h.Health == 0 then
local items = {}
local backpackItems = player.Backpack:getChildren()
for i=1,#backpackItems do
table.insert(items, backpackItems[i]:clone())
end
waitForSpawn(player)
if player ~= nil then
wait(.1)
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
---- Need Fixing Here ^
function aspawn(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(aspawn)

2 comments
You can use Instance:IsA("ClassName"). This function will check the instance in what class. For sample, you can loop though Children of the Character, and use simple if statement to check the Child is a tool or not. https://developer.roblox.com/en-us/api-reference/function/Instance/IsA
Like this: if child:IsA("Tool") then ...