Move Tool On Click

local part = script.Parent
local clickDetector = part:FindFirstChild("ClickDetector")

local function onClicked(player)
    local character = player.Character
    if character then
        local humanoid = character:FindFirstChild("Humanoid")
        if humanoid then
            -- Unequip tools before moving
            humanoid:UnequipTools()
            local tool = humanoid:FindFirstChildWhichIsA("Tool")
            if tool then
                tool.Parent = part
                tool.Handle.CFrame = part.CFrame
            end
        end
    end
end

-- Ensure that clickDetector is not nil
if clickDetector then
    clickDetector.MouseClick:Connect(onClicked)
else
    warn("ClickDetector not found in part")
end

I made a script that when I click a part, my equipped tool should go to the part. It doesn’t happen though and there are no errors

2 Likes

Pretty sure when the tool is unequipped it goes to the character and not the humanoid.

I tried

local part = script.Parent
local clickDetector = part:FindFirstChild("ClickDetector")

local function onClicked(player)
    local character = player.Character
    if character then
        local humanoid = character:FindFirstChild("Humanoid")
        if humanoid then
            -- Unequip tools before moving
            humanoid:UnequipTools()
            -- The tool now is a direct child of the character, not the humanoid
            local tool = character:FindFirstChildWhichIsA("Tool")
            if tool then
                tool.Parent = part
                tool.Handle.CFrame = part.CFrame
            end
        end
    end
end

-- Ensure that clickDetector is not nil
if clickDetector then
    clickDetector.MouseClick:Connect(onClicked)
else
    warn("ClickDetector not found in part")
end

Still doesn’t work

When a tool is equipped, it is parented to the player’s Character. Not a child of the Humanoid, just a direct child of the Character.
When a tool is unequipped, it is parented to the player’s Backpack.