Destroying specific parts with the tool

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

What is number value needed for

to create a durability that communicates with pickaxe so that it knows how many blows it has to make to break the stone, that’s what I thought

You should try add NumberValue or IntValue to Stone model then name it as “HP”
Only detected if Model has Value as example. i gonna add extra for distance limit

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

local DAMAGE=1
local MAXDISTANCE=6

Tool.Activated:Connect(function()
if Mouse.Target and Mouse.Target.Parent and(Mouse.Hit.Position-Tool.Handle.Position).magnitude<MAXDISTANCE and Mouse.Target.Parent:FindFirstChild'HP'then -- I recommend to check if model have classname Value named HP
if Mouse.Target.Parent.HP.Value>0 then
Mouse.Target.Parent.HP.Value-=DAMAGE
print('work')
else
Mouse.Target.Parent:Destroy() -- If HP it's 0
end
end
end)

Players.ElectroFLash_1.Backpack.WoodPickaxe.MineScript:3: attempt to index nil with ‘GetMouse’ - Server - MineScript:3

I get this error

Clientside

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

local DAMAGE=1
local MAXDISTANCE=6

Tool.Activated:Connect(function()
	if Mouse.Target and Mouse.Target.Parent and(Mouse.Hit.Position-Tool.Handle.Position).magnitude<MAXDISTANCE and Mouse.Target.Parent:FindFirstChild'HP'then -- I recommend to check if model have classname Value named HP
		script.Parent.RemoteEvent:FireServer(Mouse.Target.Parent,DAMAGE)
	end
end)

Serverside

script.Parent.RemoteEvent.OnServerEvent:Connect(function(p,HIT,DMG)
	if HIT.HP.Value>0 then
		HIT.HP.Value-=DMG
		print('work')
	else
		HIT:Destroy() -- If HP it's 0
	end
end)

Well i was actually show this

it works, it was my mistake that I put it in the script instead of the local script, but as an additional question, how can I make it spawn an item when that model is broken? that item is placed in serverStorage in a folder

I will try to make them some stone spawn by area you set
there i was already make example. just give me time

I noticed one thing, which I want to solve, I want it to destroy specific models, for example only the stone and already with another pickaxe to destroy other models, not all of which contain intValue (FOR ANOTHER PICKAXE I WILL DO IT ALONE AS I HAVE PICKAXES TO DO CHANGES) i

Yes it’s actually work if you just add NumberValue to any stone model then rename HP
but not put in parts
Screenshot (553)

I meant that the wooden pickaxe can only break models called Stone1, Stone 2, etc

local CanBreakLevel=1
script.Parent.RemoteEvent.OnServerEvent:Connect(function(p,HIT,DMG)
	if HIT.HP.Value>0 and HIT.Level.Value<=CanBreakLevel then
		HIT.HP.Value-=DMG
		print('work')
	else
		HIT:Destroy() -- If HP it's 0
	end
end)

Then? add another NumberValue to stone then rename as Level
Set weak stone to level 1 then add another another stone for level 2

explain in more detail that I don’t understand where to put the script and what exactly is in the script, so that I can modify it later for other stones and Pickaxes


Ok. soo example
White stone it’s level Value 1 and Red stone it’s Level Value 2
if you set pickaxe level 2 it mean you only can damage stone level 1 and 2 only

Serverside

local CanBreakLevel=1  -- Configure this Depend what stone level if level 1 it mean you can't damage level 2
script.Parent.RemoteEvent.OnServerEvent:Connect(function(p,HIT,DMG)
	if HIT.HP.Value>0 and HIT.Level.Value<=CanBreakLevel then
		HIT.HP.Value-=DMG
		print('work')
	elseif HIT.Level.Value<=CanBreakLevel then
		HIT:Destroy() -- If HP it's 0
	end
end)

wait, how to put this script over the previous script without creating unnecessary problems and errors???

You can copy above script then replace your recent serverside script

RemoteEvent is not a valid member of Tool “Players.ElectroFLash_1.Backpack.WoodPickaxe” - Client - LocalScript:2

I got this error

The dev forum is not a place to ask for full scripts. However, this topic has been covered before:

Extra Note: (If you want the part to also destroy on the server create a remote event)

1 Like

Then you forget add RemoteEvent to tool

Don’t skid. Go learn instead.