First im new to scripting this will be used for an upcoming game but i have made a pickaxe but now i cant find out how i can make it break a block Not Terrain.
So how would i make this?
First im new to scripting this will be used for an upcoming game but i have made a pickaxe but now i cant find out how i can make it break a block Not Terrain.
So how would i make this?
Assuming you have an animation already in place then just do this
Pickaxe.HitBox.Touched:Connect(function(block)
if block:IsA('BasePart') then block:Destroy() end
end)
Make sure the pickaxe hitbox doesnt touch the player or you can add an extra check to see if it does touch a player to avoid destroying player parts.
Use something like:
local mouse = game.Players.LocalPlayer:GetMouse()
mouse.Button1Down:Connect(function()
if mouse.Target ~= nil and mouse.Target:FindFirstChild("Breakable") then
mouse.Target:Destroy()
end
end)
Keep in mind that you need to put a value inside of the parts that can be destroyed.
Call the value “Breakable”.
Here is an example project:
BreakScript.rbxl (22.9 KB)
This solution is better than mine. Also if you dont want to go through the time putting each value into each part just run this in the command bar.
for i, v in pairs(workspace:GetDescendants()) do
if v:IsA("BasePart") then
workspace.Breakable:Clone().Parent = v
end
end
Make sure to put the value in workspace if your running that.
Good idea! However, as with your version, you should also consider that the pickaxe touches the block.
Because with my version you can destroy the block even at a distance.
I would not recommend using Player:GetMouse(). Using UserInputService and BasePart.Touched together is better. To avoid breaking from a distance, you can calculate the magnitude and if it’s too far then the code won’t run.