I’m working on a game that uses tools for most everything in the game. I was wondering if there is a way to make it so that when a player picks up an item, they keep holding the item they previously were, not this new one. For example, the player is holding a pickaxe to mine blocks. However, when they pick up the block they mined (it drops as a tool), they switch from holding the pickaxe to holding this block. It makes it difficult to continuously mine. If anybody knows a solution to this issue, I’d very much appreciate it if you could share it, if there even is a solution.
This code should work for this:
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
-- Store the previously held tool
local previousTool = nil
-- Handle tool equipped event
local function onToolEquipped(tool)
-- If the player is already holding a tool, store it in previousTool
local currentTool = humanoid:GetEquippedTool()
if currentTool then
previousTool = currentTool
end
if previousTool == nil then
tool.Parent = humanoid
else
previousTool.Parent = character
tool.Parent = humanoid
end
end
-- Connect the tool equipped event to onToolEquipped function
humanoid.ToolAdded:Connect(onToolEquipped)
This does what you described, feel free to tell me if it doesn’t work!