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?
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!