When you add a tool to custom backpack, it doesn't wont to work

Hello,
I’m extremely tired so ill just post the script and the problem.

local TableOfNumbers = { -- Necessary
	[1] = "One",
	[2] = "Two",
	[3] = "Three",
	[4] = "Four",
	[5] = "Five";
	[6] = "Six";
	[7] = "Seven";
	[8] = "Eight";
	[9] = "Nine";
	[10] = "Zero";
}

local TableOfItems = { --Necessary
	[1] = false,
	[2] = false,
	[3] = false,
	[4] = false,
	[5] = false;
	[6] = false;
	[7] = false;
	[8] = false;
	[9] = false;
	[10] = false;
}
function IsToolInTable(tool)
	for i, v in pairs(TableOfItems) do
		if v == tool then
			return true
		end
	end
	return false
end


function AddTool(tool, choice)
	if not IsToolInTable(tool) then
		local availableIndex = 1
		while TableOfItems[availableIndex] do
			availableIndex = availableIndex + 1
		end
		
		TableOfItems[availableIndex] = tool
	else
		-- Allow duplicate tool through
		return
	end
end


plr.Backpack.ChildAdded:Connect(function(child)
	if not child:FindFirstChild("AllowThroughBackpack") then
		AddTool(child)
		refreshGUI()
	else
		child:FindFirstChild("AllowThroughBackpack"):Remove()
		refreshGUI()
	end
end)

UIS.InputBegan:Connect(function(IP,GP)
	if GP then return end
	
	for i,tool in pairs(TableOfItems) do
		if TableOfNumbers[i] then
			if IP.KeyCode == Enum.KeyCode[TableOfNumbers[i]] then
				if tool ~= nil or tool ~= false then
					for i2,tool2 in pairs(plr.Backpack:GetChildren()) do
						
						
						
						local chara = plr.Character:FindFirstChildWhichIsA("Tool")
						
						print("true")
						print(tool2)

						if chara then
							print("found a tool")
							if chara == tool then
								print("they are the same")
								game.ReplicatedStorage.ServerEvent.BackpackEvent:FireServer(false)
								break
							else
								game.ReplicatedStorage.ServerEvent.BackpackEvent:FireServer(true,tool)
							end
						else
							game.ReplicatedStorage.ServerEvent.BackpackEvent:FireServer(true,tool)
							break
						end
					end
					break
				end
			end
		end
	end
end)

Whenever I equip a tool (that’s already in the starter pack), it works but then when i move that SAME tool from backpack2 to backpackmain, it doesn’t want to function.

So whenever you add a tool to THE MAIN BACKPACK, it doesnt work.

Dont question about the tools, the tools already work, even without the backpack script.

Theres another script which this is linked to but its mainly just Humanoid:Equiptool() ( WE SHALL CALL THIS EQUIPSCRIPT )

Here’s basically many ways that it doesnt want to work:

Error Number 1:

  1. Move tool from backpack2 to backpackmain
  2. It prints that the tool has been equipped. (EQUIPSCRIPT prints this)
  3. The tool is in the players inventory but it falls out the map anyways.

Error Number 2:

  1. A New tool is added (it does not share the same name with any other tool).
  2. It prints that the tool has been equipped. (EQUIPSCRIPT prints this)
  3. The tool is in the players inventory but it falls out the map anyways.

Error Number 3:

  1. A New tool is added and it shares the same name as another tool.
  2. It prints out nil has been equipped. (EQUIPSCRIPT prints this)
  3. The tool is not in the players inventory.

That’s all the errors that occur in this,
if you need more information dm me but i wont be online for at least 20 hours.

Please try and help me the best of your ability.

1 Like

Thanks.

The error is coming from this section of your code:
game.ReplicatedStorage.ServerEvent.BackpackEvent:FireServer(true,tool)

This is trying to invoke a remote event on the server and pass it two arguments, but BackpackEvent requires three arguments: a boolean, a player, and a tool.
You are passing it a boolean and a tool, which is why you are getting the error.

the player is automatically added to the event on the script anyways (since its a local script firing to a server script)

I’ve just fixed Error Number 3 by using server sided script and using it to add tools from there. But Number 1 and 2 carry on breaking.

Do you still need help with this?

Error 1 and Error 2 is still consistent [yes]

sorry for the delayed response, but are you sure that the issue isn’t that the tool’s part isn’t a handle or it isn’t welded to the handle? also, i recommend using fewer lines of code because writing code with too many lines can make it really hard to read. additionally, you ought to use more variables and functions as that makes it a lot easier to handle. could you show the server sided script? i don’t think that’s the problem but just in case