Overriding or disabling tool dropping

Currently pressing Backspace when a tool is equipped does one of these two things:

  • If tool.CanBeDropped is false, the tool is returned to the player’s backpack
  • If tool.CanBeDropped is true, the tool is parented to the workspace

I would like a way to disable or override this behavior. For example, I want to delete the tool when the player presses backspace instead of parenting it to either of those two locations. This is what I have to resort to currently:

local lastBackpackTool = nil
local tool = nil
local textBoxHasFocus = false

local player = game:GetService("Players").LocalPlayer
local backpack = player:WaitForChild("Backpack")
backpack.ChildAdded:connect(function(child)
	if child:IsA("Tool") then
		lastBackpackTool = tick()		
		tool = child
	end
end)

local userInputService = game:GetService("UserInputService")
userInputService.TextBoxFocused:connect(function() textBoxHasFocus = true end)
userInputService.TextBoxFocusReleased:connect(function() textBoxHasFocus = false end)

local function checkForRecentlyRemovedTool()
	if lastBackpackTool and tick() - lastBackpackTool <= .1 then -- arbitrary number
		lastBackpackTool = nil
		tool:Destroy()
	end
end

game:GetService("UserInputService").InputBegan:connect(function(inputObject, gameProcessedEvent)
	if not gameProcessedEvent then
		if inputObject.KeyCode == Enum.KeyCode.Backspace then
			checkForRecentlyRemovedTool()
		end
	end
end)
33 Likes

With hat dropping recently losing its status as a built-in feature I think it makes a lot of sense to look at tool dropping as well.

11 Likes

If I’m not mistaken the logic for the backspace key dropping tools is completely implemented in the engine. It might be viable to move this so you could achieve custom behavior by completely disabling the backpack using StarterGui:SetCoreGuiEnabled() and implementing a completely custom backpack. This might be game breaking for games that already implement custom backpacks though.

Another option: It’s a bit unconventional but maybe we could add a callback on Backpack which deals with this, if the callback is being used then it would be called when a user attempts to drop a tool and the regular behavior would not apply. Something like Callback DropToolRequested(Tool toolInstance, InputObject input).

5 Likes

@TheGamer101 It would be nice if the backpack core script was moved to a player script, but I would still want an easy way to change this functionality without overriding the entire script.

5 Likes

A potential issue is that this functionality isn’t currently controlled by the CoreScript (as far as I know). Moving it to the CoreScript (or to a PlayerScript version of the script) would cause an issue for developers already overriding the backpack script.

1 Like

The backpack script is a core script though, right? So I don’t see the problem in moving the hotkey logic to Lua.

2 Likes

If there are games that expect the tool dropping behavior to work even though the backpack UI is disabled with SetCoreGuiEnabled then this change could potentially negatively effect those games.

3 Likes

I know that dropping a tool often fixes it if it is broken. And I know it doesn’t work on all tools, yes.

1 Like

Is this something that can be revisited at all? Perhaps some kind of bool that defaults to true to prevent breaking games relying on backspacing tools?

For me personally, I have an insanely hard time working with custom inventories. Tools are an easy solution so that I don’t have to manually code inventories, then tools on top of that (the current script layout is EXTREMELY ugly and hard to work with). The only reason I go through such lengths writing inefficient and terrible code is because with a custom inventory, I have full control over tool behavior, including:

  • Not being dropped or returned to the inventory on backspace depending on CanBeDropped property
  • Not playing an animation to hold the tool on equip (have to make a custom Animate script; would like some tools to play hold animation while others not doing so)
  • Having control over the Backspace KeyCode
  • Having control over KeyCodes relating to 0-9 (which would normally be used to pick tools based on organization in one’s backpack)

It could also kickstart a “custom inventory” feel for new developers who are not as experienced. They can have custom systems that call Humanoid:EquipTool() and Humanoid:UnequipTools() that use real tool instances and don’t get dropped when pressing backspace. With that, they can also hide the Backpack CoreGui.

9 Likes

I think that this should be revisited, too. I feel like the idea of pressing backspace in order for a tool to be put in the backpack is rather unneeded. There should be an option to remove the backspace use with tools as a whole, as said earlier.

This could be beneficial to prevent games from breaking while still giving those of us who want this feature the ability to implement some sort of custom behavior for backspace, or no behavior at all.

Colbert’s post sums up most of what I think about this.

1 Like

I’m begging for this.

-Move the backspace code to playerscripts so we can choose to disable it if we want.

and/or

-Use ContextActionService instead of UserInputService so we can bind over top of the default backspace behavior. (or unbind it)

5 Likes

If your use-case is to not allow players to drop tools, you can set the Tool property CanBeDropped to false.

If this does not help, could you provide more context to your use-case?

7 Likes

I want to keep a tool in the player’s hand at all times. It’s a for First Person PvP game (basically any AAA shooter does this).

But they can just hit backspace and put the weapon in the backpack (even though I disabled the coregui).

I don’t want to have to set up a hacky loop that checks to see if they have no tool equipped just to put it back in their hands.

(I basically should be using a custom backpack with custom tools at this point, but I thought for sure that by now there would be a way to do this and there isn’t.)

2 Likes

What functionality are you looking to get from using a tool instead of without?

5 Likes

Using a tool was just a lot easier than creating a complicated system just for one weapon. And it does almost everything I need it to, except always stay in the hand XD Tools were just the easiest option that required the least amount of effort.

5 Likes

I can vouch for this use case, I’m encountering this issue right now.

I want the player to Equip the tool at all times, and would like to avoid making a custom tool system.

Currently if you press Backspace the tool will go into the backpack and can never be retrieved again because I have the default Backpack disabled.

And I am using Keys 0 - 9 for other things.

It might be possible to bind Backspace to an empty function, if that fails just use .Unequipped and put it back into Player.Character for now.

13 Likes

I am still in great support and desire for this feature to become a reality. As a Roblox developer, I want more control over the Tool instance. Tools are already a solid, easy-to-use and familiar feature that allow us to give players a way to use certain items in experiences but we lack more control over them. I have experiences where I want a player having a tool equipped at all times and backspace prevents that with no way to override it.

I am currently forced to reinvent the wheel for tools and write the backend by myself just to get rid of this one behaviour of tools being unequipped when backspaced. It’s not something I can’t do but it’s tiresome and annoying when I have to write this for multiple projects and it’s difficult for novice developers to make a “true force unequip” system (you have to reparent the tool when its unequipped and that continuously triggers Equipped or interrupts tool scripts which is entirely undesired).

Backspace is literally the only thing that turns me away from using Tools unless I have an experience where it doesn’t matter if backspace is triggered.

6 Likes

Support. I cannot use tools for a decent portion of games as having a tool be constantly out can be important, and is a standard for a majority of shooters. Because of this problem, I have to create/utilize complex gun systems so I can have this simple behavior. This is unacceptable.

1 Like

I already do this for my game, I didn’t realize until reading this that others were having an issue with this. I use the default tool bar from Roblox. If you want to over-ride this behavior, simply tag a tool with an attribute of some kind, then if the player tries to unequip the item, the server just re-quips it right back instantly. Solves the issue without disabling the tool drop (in case you want to use it for something else) If they add a feature to disable the default behavior, then I won’t complain, but currently there is a solution to the issue presented here.

4 Likes

I’m a little confused by what you mean by ‘tagging a tool with an attribute of some kind.’ Could you elaborate further or explain what you mean more in depth?