Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to remove tool while player is holding?

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?

3 comments

0

Use the :Destroy() function

0

I've tried...

0

What happened?

1 answer

✓ Accepted answer
  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!

4 comments

0

This works great! but it doesnt remove the specific tool, It removes whatever tool it touches

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

0

Thank you Antonin

0

Worked! Ty so much

This discussion is preserved as it was. New answers, comments, and votes are closed.