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

How to search a player's backpack?

Asked by 9 years ago

This is the code:

01script.Parent.Slot.MouseButton1Down:connect(function()
02    playerName = script.Parent.Slot.Text
03    print(playerName)
04    local backpack = game.Players:FindFirstChild(playerName).Backpack
05    print(backpack)
06    local toolFrame = script.Parent.Parent.ToolFrame.Tool  
07    for i,tool in pairs(backpack:GetChildren()) do
08    print("ok")
09    if tool then
10    local tool = toolFrame:Clone()
11    tool.Parent = script.Parent.Parent.ToolFrame
12    tool.Name = "Tool"--..slotnum
13    tool.Position = UDim2.new(0,0,0,55*num.Value)
14    tool.Text = tool.Name
15    tool.Visible = true
16    end
17    end
18end)

The function works until the for loop. But I'm not getting any error. What am I doing wrong? Help is greatly appreciated!

3
Maybe there's nothing in the Backpack. User#6546 35 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

Maybe the "toolFrame" cannot be found OR the backpack array is empty, make sure you debug the code.

Ad

Answer this question