Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to search a player's backpack?

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!

1 comment

3

Maybe there's nothing in the Backpack.

1 answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.