I'm making a tool that takes the items from the players backpack upon death and stores it in a folder inside another tool. I got the spawning down but for some reason the items won't transfer into the tools folder. For now I am using swords and guns but my tools aren't gonna have any bricks so the workspace won't be an issue...
First I tried
local humanoid = script.Parent:WaitForChild("Humanoid") local hrp = script.Parent:WaitForChild("HumanoidRootPart") local plr = game.Players:FindFirstChild(script.Parent.Name) humanoid.Died:Connect(function() local clone = game.Lighting.Tools.Runes:FindFirstChild('Skill Rune'):Clone() clone.Parent = workspace clone.Handle.Position = hrp.Position + Vector3.new(math.random(-5,5), 0, math.random(-5,5)) local plrskills = plr.Backpack:GetChildren() plrskills.Parent = clone.Skills end)
Then I tried
local humanoid = script.Parent:WaitForChild("Humanoid") local hrp = script.Parent:WaitForChild("HumanoidRootPart") -- this is assuming the npc model has a Torso local plrn = script.Parent.Name local plr = game.Players:FindFirstChild(plrn) humanoid.Died:Connect(function() local clone = game.Lighting.Tools.Runes:FindFirstChild('Skill Rune'):Clone() clone.Parent = workspace clone.Handle.Position = hrp.Position + Vector3.new(math.random(-5,5), 0, math.random(-5,5)) local plrskills = plr.Backpack:GetChildren() for _,v in pairs(plrskills) do if v:IsA("Tool") then v.Parent = clone:FindFirstChild('Skills') end end end)
Both do not function correctly, or at all actually!
I think I see your problem. In your first script, you are trying to parent plrskills
, which is a dictionary object, to your tool. You need to iterate over all the items in that list and parent each separately. The problem in the second script is that you are using pairs()
. Pairs creates number-value pairs in non-indexed lists, but when you use :GetChildren()
, you are creating an indexed dictionary. Try using ipairs()
in the second script instead.