How would I script a tool which would destroy a part with a certain material e.g. part.Material == "Sand"?
I made a tool which my player can hold as a starting point by adding a handle. How would I make it so that if a player touches an object with the sand material the tool in its hand the part will destroy?
how would I use the destroy() function?
Also, previously I made this code which would make the transparency of an object 1 and cancollide false so you can remove the object where you cant see it and wont collide into it but I don't know where to place it as a local script in my tool with the local script in the tool and not in the handle but when I tried nothing happened when i clicked on the part I wanted to make transparent which was called Terrain and nothing happened and I had the tool equipped.
Code I used previously:
script.Parent.Activated:Connect(function(mouse) if mouse.Hit.Name == "Terrain" then step = .1 waitC = .1 for i=0,1 step do mouse.Hit.Transparency = i wait(waitC) end mouse.Hit.CanCollide = false end end)
Thank You and help is appreciated
yourtoolhere.Touched:connect(function(hit) --if your tool touches something if hit.Material = "Sand" then --if what it touched has sand material hit:Destroy() --destroys what it touched end)
This code should help you, if your stuck just let me know.
First make the tool. I'm not going to explain how to make a tool. Then make a part and add this script into it:
script.Parent.Touched:connect(function(hit) if hit.Parent.Name == "YourToolNameHere" then game.Workspace.Part:Destroy()
If you want to make the tool destroy more parts, add this script into other parts as well. Hope this helps!