Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i make it so only parts with a specific name unanchor?

Asked by 4 years ago

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)
0
You have to specify what the part is going to get hit by like a human a hammer i think that is why also which type of script is it? StevenElijah7019 57 — 4y
0
and you have to specify what part it is it or name StevenElijah7019 57 — 4y
0
check if the Name of hit is "Breakable"? DeceptiveCaster 3761 — 4y

2 answers

Log in to vote
1
Answered by 4 years ago

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:

if statements in Lua

Instance.Name

Script vs Localscript

Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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)
0
He only wanted to check for "Breakable" blocks and unachor them. If you want this done recursively then cool. Doge_Brigade 94 — 4y

Answer this question