Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to remove tool while player is holding?

Asked by
WH_HAN 2
4 years ago

Hello! I'm trying to make a script that when a specific tool touches a part it will remove the tool, Also the player has to be holding the tool in order for it to get removed. I have searched online but I can't find anything that works. Here is my code:

script.Parent.Touched:connect(function(p)
    if p.Parent.Name == "Box" then
        script.Parent.Transparency = 0
        script.Parent.CanCollide = true

    end
end

ik my code is really short. Can anyone please help me?

0
Use the :Destroy() function 0Papa_Rat0 63 — 4y
0
I've tried... WH_HAN 2 — 4y
0
What happened? User#30567 0 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago
  script.Parent.Touched:Connect(function(p)
    if p.Parent:FindFirstChild("Humanoid") then
        if p.Parent:FindFirstChild("Box") then
            p.Parent:FindFirstChild("Box"):Destroy()
        end
    elseif p.Parent.Name == "Box" then
            script.Parent.Transparency = 0
                script.Parent.CanCollide = true
     end
 end

With this event, it will check if the user has a humanoid, which can be a player or NPC and then checks if it contains an instance that has the class of 'Tool'. FindFirstChildOfClass returns the instance if it does find an instance of class 'Tool' in the character and then ultimately destroys it.

[EDIT] I make the script check for an instance named 'Box', if so, it destroys it, please replace it to your toolname and it should work!

0
This works great! but it doesnt remove the specific tool, It removes whatever tool it touches WH_HAN 2 — 4y
0
@InedibleGames put your answer's script in a code block, if you don't know how just click on the little lua icon when editing/answering and it will make a "box" for you to put your script in and make it more readable AntoninFearless 622 — 4y
0
Thank you Antonin InedibleGames 150 — 4y
0
Worked! Ty so much WH_HAN 2 — 4y
Ad

Answer this question