Disabling unequipping or keys to unequip?

I’m trying to prevent the player from unequipping their weapon. The player has 3 weapons in their backpack, and they can press 1, 2, 3 to change each weapon. However if a player tries to unequip the weapon they can’t re-equip them (I’ve disabled the backpack UI)

So I need a way to completely prevent them from removing an item from them. The only way is to change weapons via 1, 2, 3.

I tried using the UnEquipped function to basically re-equip if they try to unequip it, but that also prevents them from using 2 and 3 to change their weapons.

I’d prefer to know of a way to completely prevent unequipping, as I don’t want to have to disable the backspace button (and whichever button unequips on the xbox)

Not sure if someone has button in a request for a feature to be added to tools like CanBeDropped, but instead ‘CanBeUnequipped’, which basically prevents them from unequipping unless told to do so by code

6 Likes

If you don’t wait a tool to be unequipped, don’t use a tool. Weld the weapon to the character instead.

Got no clue how to do that + would have to re-code almost everything as the weapons code is tool based and also when it comes to getting animations, idk how they work, but don’t wanna spend money getting them done only to be told that they have to be done in a tool.

Use metatables (in a module) to make your own functions. It won’t require a huge re-code either, just use your new functions instead of tool.Unequipped, tool.Equipped, etc.

This is my code for it (kind of ugly in my eyes):

game:GetService("Players").PlayerAdded:connect(function(player)
	local function hookTool(tool)
		if not tool:IsA("Tool") then return end
		game:GetService("RunService").Heartbeat:wait()
		tool.Parent = player.Character
	end
	
	player:WaitForChild("Backpack").ChildAdded:connect(hookTool)
	
	player.ChildAdded:connect(function(child)
		if child:IsA("Backpack") then
			child.ChildAdded:connect(hookTool)
		end
	end)
	
	for i,v in pairs(player.Backpack:GetChildren()) do
		hookTool(v)
	end
end)
3 Likes

What part of the code prevents them from unequipping? I haven’t tested it, but just looking at it, if they press backspace wouldn’t it still just disappear or am I missing something?

It’ll disappear for about a single frame then immediately come back (put back into their parent). The tool does visually disappear in the meantime which is kind of disappointing.

2 Likes

Here, if a child is added back to the backpack (aka your tool) it will re-equip it.

3 Likes

What that ended up doing is equipping all 3 items in my backpack. I just want it to re-equip the item that I unequip, not everything in the backpack

1 Like

Yeah my code only works for me since I only have one tool. You should be able to adapt it in some way though.

If I remember correctly, the ContextActionService handles tool unequiping and therefore can be unbound. I’d call ContextActionService:GetAllBoundActionInfo() to see if the tool equip/unequip actions are bound here, and try using UnbindAction(). I also noted UnbindActivate which says that it can remove keys used to activate/deactivate Tools and HopperBins which were set with BindActivate. Maybe it can remove the default keys too?

1 Like

It does not.

The comment in the OnInputBegan callback literally says:
Pass through [...] (except for the Drop key)

:confused:

Its for little things like this that I never use the Tool or HopperBin instances anymore.

4 Likes

So basically it’s impossible? :confused:

There are some workarounds, like reequipping it right after the player unequips it, or just not using Tools as discussed above. But as for a good solid method to disable it: no.

1 Like