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

Target specific descendants only?

Asked by 4 years ago

I have a script that finds a folder that contains a model of a grappling hook. It's supposed to only change the transparency of descendants whose name are "Union" "a" or "b".

local descendants = game.Workspace.grapples.grapple:GetDescendants()
for index, descendant in pairs(descendants) do
    if descendant:IsA("BasePart") or descendant.Name == "Union" or descendant.Name == "a" or descendant.Name == "b" then
        descendant.BrickColor = BrickColor.new("Really red")
        descendant.Transparency = 0
    end
end

Obviously the script doesn't work because I'm not changing what "descendant" refers to, I'm only changing the if statement so all parts in the model become visible. My question is how can I target only the descendant with those specific name?

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

old version:

local descendants = game.Workspace.grapples.grapple:GetDescendants()
for index, descendant in pairs(descendants) do
    if descendant:IsA("BasePart") or <--delete this and keep the rest descendant.Name == "Union" or descendant.Name == "a" or descendant.Name == "b" then
        descendant.BrickColor = BrickColor.new("Really red")
        descendant.Transparency = 0
    end
end

new version

local descendants = game.Workspace.grapples.grapple:GetDescendants()
for index, descendant in pairs(descendants) do
    if descendant.Name == "Union" or descendant.Name == "a" or descendant.Name == "b" then
        descendant.BrickColor = BrickColor.new("Really red")
        descendant.Transparency = 0
    end
end

Ad

Answer this question