Destroying specific parts with the tool

I’m trying to make a script that when you press on a part with a pickaxe, that part and that part will break, can you help me?

3 Likes

I think a simple way is adding a touched event on the pickaxe and checking if hit.Name is the name of the part you want to break using :destroy() but there are definitely better ways to do that.

Here’s a script that could help:

’’
local Tool = script.Parent
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

Tool.Equipped:Connect(function(mouse)
mouse.Button1Click:Connect(function()
if mouse.Target:IsA(“Part”) then
mouse.Target:Destroy()
end
end)
end)
’’

Now this might not be 100% accurate script because I’m in phone but that’s the best thing I could help, and also this is a client sided script.

but if I want to break all the parts that are in certain files and the rest of the remaining files can’t break them?

you can check for the part’s parent

not work, i tested now, what can i do??

If you want to break all of the parts, you must use:

``for i,v in pairs(Folder:GetChildren()) do

end
``

Does it prints errors in the output?

no, just ignore my script :((((((

I’m pretty sure they’re the same, because you’re naming them with your own.

Show me your script so that I can take a look

if you got the mouse argument of the function then you don’t need to assign a seperated Mouse Variable since you won’t be using it

make sure its a localscript as you cant get the player’s mouse from a serverscript

my script
Screenshot 2024-07-22 163359

but I want to make the pickex able to break only 1 what is in the stones file that will randomly appear in the world
Screenshot 2024-07-22 164205

it’s just in development, but in the future everything will be as it should be, haha

there is no such instance called “Stone1” if you want to check for the name then do if Mouse.Target.Name == "Stone1" then

it doesn’t work again, what did I do wrong? I’m sorry if I explain badly and bring information along the way, but any help is welcome

show the script and is there a part/parts named Stone1 in workspace?

I put one on just for testing

Screenshot 2024-07-22 165234

mouse target can’t detect models, instead it detects the inside of it, so you can just check whats inside the model and then delete its parent (which is the model)

1 Like

how can i do this??? and how can I add durability, i.e. stone has durability of 20 and pickaxe does -5 for durability until it breaks, btw, stone has NumberValue added