Ways to find an element in Workspace?

imagine the following situation: an x ​​value can be an element that is in two different models in Workspace.
This “x” value can be between these two models(Level 1 and Level2):
faffaf
How would I find this element? Let’s assume its name would be: “Level”. That is, I want to find an x ​​element called “Level”, How would I do this without repetition?

I tried the following:

local function FindCframeValue ()
				
					
					for i,v in pairs (workspace.CheckpointsLevels:GetChildren()) do
						if v.Name == Element.Name then
							return v.CFrame
						else
							for i,v in pairs (v) do
								if v.Name == Element.Name then
									return v.Cframe
								else
									--more ForLoops
								end
							end
						end
					end
				
				
			end

until it works, but it’s not practical

Couldn’t you use :GetDescendants() instead? You could also use recursion but the former would probably be better.

then you suggest something like:

for i,v in pairs (Workspace.CheckpointsLevels:GetDescendants())
--code
end

?

Yes. That would look for everything in the folder.

1 Like

I feel like an idiot.Thanks for help!