Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to take tools from players inventory then put into folder?

Asked by 5 years ago

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!

0
Ok, first of all, use indentation properly. Secondly, why are you using Lighting to store stuff?! Use ServerStorage or ReplicatedStorage. Next, set all the properties of an object before parenting it. Lastly, keep in mind that tools can be found in two places; the character if they are equipped, or the backpack if they are not. Also, use CFrame, not Vector3, as that can cause some issues. RiskoZoSlovenska 378 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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.

Ad

Answer this question