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:

script.Parent.Slot.MouseButton1Down:connect(function()
    playerName = script.Parent.Slot.Text
    print(playerName)
    local backpack = game.Players:FindFirstChild(playerName).Backpack
    print(backpack)
    local toolFrame = script.Parent.Parent.ToolFrame.Tool   
    for i,tool in pairs(backpack:GetChildren()) do
    print("ok")
    if tool then
    local tool = toolFrame:Clone()
    tool.Parent = script.Parent.Parent.ToolFrame
    tool.Name = "Tool"--..slotnum
    tool.Position = UDim2.new(0,0,0,55*num.Value)
    tool.Text = tool.Name
    tool.Visible = true
    end
    end
end)

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 8 years ago

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

Ad

Answer this question