I have a hammer that makes parts unanchor when they get hit by it, but i only want it to break blocks that are named "Breakable". Here's my script:
local function onTouch(hit) hit.Anchored = false end script.Parent.Touched:Connect(onTouch)
We know that we want to set the Anchored
property to false
whenever the part's name is Breakable. To achieve this, you can simply add an if statement inside your event, check if the name indeed is Breakable and if so, set the anchor to false
. To check a name, the property's name is simple: Name
.
if (part.Name == "Breakable") then part.Anchored = false end
You add this to your code, in your case the part is called hit
.
Also it is worth noting that if this is a local script, then this will be executed client-side and therefore only visible by the player that this script ran on. You'll likely want this to be in a script for it to be visible to everyone.
Resources:
it can be done by looping through the workspace or any service and get the baseparts and check if their name is unbreakable, I recommend making this a function so you can check any folder, and also to make a table for names that make the part anchored and then check for the parts
local names = {"Unbreakable"} local function checkForParts(folder) if folder then for _, v in pairs(folder:GetDescendants()) do if v:IsA("BasePart") and table.find(names, v.Name) then v.Anchored = false end end end end) script.Parent.Touched:Connect(function(hit) checkForParts(hit.Parent) end)