How can I change the default backpack to make it so I can't unequip a tools, but I can switch between them

I want to make a backpack that does not allow the player do unequip a tool, but allows the player to equip another. If no one can find a solution for this, I’ll simply just make my own tool system without the default ROBLOX one.

Well, you simply have to detect where the tools are at.

When the tools are located within Player.Character, it means that the player is actively holding them. When the tools are located within Player.Backpack, it means that the player is storing them in their backpack/inventory.

Now, to check whether or not these switch, this simple function should help:

Player.Backpack.AncestryChanged:Connect(function(tool, toolparent)
   if tool:IsA("Tool") then
       if toolparent:IsA("Model") then
          return
       else
          Player.Character:EquipTool(tool)
       end
   end
end)

I didn’t test this, by the way. Let me know if it works.

--localscript in StarterStaracterScripts

local char=game.Players.LocalPlayer.Character

game:GetService('UserInputService').InputBegan:Connect(function(input)
  for _,tool in pairs(game.ReplicatedStorage.Tools:GetChildren())do
   -- tools folder
     if input.KeyCode==v.order.Value and not char:FindFirstChild(v.Name)then 
--[[ You need to create an 'NumberValue' with name 'order' in each tool --]]
       for _,currentTool in pairs(char:GetChildren())do
           if currentTool:IsA('Tool')then  currentTool:Destroy() end
      end
    
       v:Clone().Parent=char
       break 
    end
  end
end)

When you press a key, this function is activated, further if this key is equal to the string value ‘order’ in the tool and if the tool is not already applied then all the tools in the player are checked and if they are, then they are deleted, and then the tool is applied.
for example if order value in tool == 4 then if the player pressed 4 key the tool is equipping.

‘break’ is used to prevent duplicate tools with the same ‘order’ value

if ‘4’ order value isn’t working use ‘Enum.KeyCode.4’

it doesn’t work for some reason, i implemented it like this

game.Players.PlayerAdded:Connect(function(Player)
	Player.Backpack.AncestryChanged:Connect(function(tool, toolparent)
		if tool:IsA("Tool") then
			if toolparent:IsA("Model") then
				return
			else
				Player.Character:EquipTool(tool)
			end
		end
	end)
end)

Mind telling me the error, so I can fix it?

no errors show up when testing, though one of them seems to be the fact that u put

Player.Character:EquipTool(tool)

when it should be

Player.Character.Humanoid:EquipTool(tool)

but still, even after i fixed that it still does not work.

Nice catch. I’ll look over it in a moment to see if I can fix it.

Yeah no. I got it to work by using something differnt and It’s really buggy and kinda un-smooth. I’ll make my own tool/backpack system. thank you for the help though!

1 Like