Made a super basic script that’s supposed to parent a tool from a folder called “Inventory” to your actual backpack. Problem is it is erroring for some reason
Workspace.GiveTools.GiveTools:8: attempt to index nil with 'WaitForChild'
local deb = false
wait(3)
script.Parent.Touched:Connect(function(hit)
if hit then
if hit.Parent:FindFirstChild("Humanoid") and deb == false then
deb = true
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
for i,v in pairs(player:WaitForChild("Inventory"):GetChildren()) do
if v:IsA("Tool") then
v.Parent = player.Backpack
end
end
deb = false
end
end
end)
That makes more sense. I tried to add wait(3) but this is more efficient. Thanks!
Final script
local deb = false
script.Parent.Touched:Connect(function(hit)
if hit then
if hit.Parent:FindFirstChild("Humanoid") and deb == false then
deb = true
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
for i,v in pairs(player:WaitForChild("Inventory"):GetChildren()) do
if v:IsA("Tool") then
v.Parent = player.Backpack
end
end
end
deb = false
end
end
end)