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
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.
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)
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.
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?
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.