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

Creating something like a FindFirstDescendant?

Is there a way I can create something that's similar to a hypothetical FindFirstDescendant? I know such a thing doesn't exist, but I have multiple models where, in order to use FindFirstChild, I would have to dig through the many models INSIDE the models, and give each one a unique name. Is there a way I can avoid doing that, and simply say, within a script, to find a brick by a certain name, that's a descendant somewhere in Workspace?

Right now, here's the relevant script...it's a LocalScript, if that makes a difference:

local plr = game.Players.LocalPlayer
local dour = workspace:FindFirstChild("TTDoor1") --Not actually a child; it's a descendant somewhere
print(dour.Name)

2 answers

I guess this is what you want.

for _, v in pairs(workspace:GetDescendants()) do
	if v.Name == "TTDoor1" then
		print(v)
		v.BrickColor = BrickColor.new("Bright green")
	end
end

5 comments

0

^ Do you think a break could work also, to prevent it going higher and looking for more?

0

No, you don't need to add break, return and debounce to stop the loop unless if you have more objects that are same names. For examble you have 4 TTDoor1 object the output will be TTDoor1 (4).

0

So to use it as a variable to later use in an if statement, would I just say "local dour = v" inside that v.Name=TTDoor statement?

0

You don't need to add variable. You can replace the "v" into "dour".

0

But if you want to make a variable of your door you need to make a table and decode it into an object. If you have so many "door" and you just put a normal variable, only just one can be handled.

Instead of FindFirstDescendant(descendant), do FindFirstChild(descendant, true).

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