Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Target specific descendants only?

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

✓ Accepted answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.