Disable Auto Equip Tool on Pickup?

I’m trying to modify the default behaviour of what happens when a character walks over a tool in the world.

Currently what happens is when a player walks over a tool, the player automatically equips this. I have a custom inventory system, so I’d like to disable this behaviour and add the tool directly to the player’s backpack.

Any ideas on how I can manage to achieve this? Adding a script to each tool isn’t an option here. I’ve tried looking for the core script that handles this but I haven’t been able to find it.

2 Likes

Tools will only be picked up when touched if there’s a BasePart called “Handle” as a child of the Tool (even if Tool.RequiresHandle is false, that’s not what that property controls). So you can disable picking up Tools by temporarily changing the Name of the Handle to something else, like “HandleDisabled”. However, it needs to be changed back to “Handle” again when the Tool is actually equipped, because it needs a Handle to know how to function properly. Here’s an example script that will disable picking up it’s Parent Tool, and then implement it again, just to show how that could be achieved:

local tool = script.Parent
local handle = tool:FindFirstChild("Handle") or tool:FindFirstChild("HandleDisabled")

function enablePickup()
	handle.Name = "Handle"
end

function disablePickup()
	handle.Name = "HandleDisabled"
end

function equip(humanoid)
	humanoid:EquipTool(tool)
	enablePickup() --Necessary for the tool to funciton while equipped
end

disablePickup()

tool.Unequipped:Connect(function()
	disablePickup()
end)

handle.Touched:Connect(function(limb)
	local character = limb.Parent
	if character then
		local humanoid = character:FindFirstChild("Humanoid")
		if humanoid then
			equip(humanoid)
		end
	end
end)
8 Likes

I don’t think that solves OP’s problem. OP doesn’t want to disable tool pickup on touch. They just want to stop it from being equipped immediately after being picked up.

Hne’s not trying to disable tool pickup completely, he just wants to disable the equipping on pickup.

You could probably do something like this

local Player = game.Players.LocalPlayer
local Char = Player.Character or Player.CharacterAdded:wait()

local Tools = {}

for I, v in pairs(Player.Backpack:GetChildren()) do
     Tools[v] = true
end

Char.ChildAdded:connect(function(Obj)
     if Obj:IsA(“Tool”) and not Tools[Obj] then
          Tools[Obj] = true
          Tool.Parent = Player.Backpack
     end
end)

Sorry if it’s sloppily typed, had to type on mobile. This should save all of the player’s starting tools in a table. If a tool is added to the character, check if it’s in the table. Yes? Keep it equipped. No? Unequip it and add it to the table.

7 Likes

I guess I could implement this same concept into my existing code.

Thank you! :slight_smile:

1 Like

Doesn’t that trip a warning? I usually get a Parent setter confliction warning whenever I try forcing equip methods like this, given that equipping is done by reparenting tools.

I have a script that’s supposed to force unequip all tools of a player and I have it handled by running Humanoid:UnequipTools() if ChildAdded fires with a Tool instance class. The tool doesn’t get equipped because it conflicts with the backend thread that parents tools to equip them at all.

2 Likes

In that case, the code I posted earlier could help with that. Instead of having the player pick up and equip tools when touched, it could put the tool in their Backpack.

1 Like

Put a wait() before reparenting. Should do the trick.

The thing is that for the approximate 1/30th of a second that the execution thread is slept for, the feedback for forcing tools unequipped isn’t instantaneous.

Off topic comment

For my own use case, I’m looking at force-clearing any tools added to either the Player or the Character. I’d prefer to force unequip to avoid any edge cases or non-instant feedback, though.