Find the name of the model from the part

Hi, I have a question.
In this image we can see that I have some models and inside of Model “D” is a part,

RobloxStudioDPart

Let’s imagine that I only know what the model “D” and the part inside are called, how could I know which is the main Model (“A”)

RobloxStudioAPart

I tried to use FindFirstAntecesor but I stopped because if I don’t have the main part string it can’t search for it

Any help is appreciated

If you have the parent of that ancestor, you could use GetChildren and IsDescendantOf

local Ancestor = nil
local Object =
Folder = 

for _,v in pairs(Folder:GetChildren()) do
	if Object:IsDescendantOf(v) then
		Ancestor = v
		break
	end
end

Use Instance | Roblox Creator Documentation to find the model ancestor and use a while or repeat loop to keep finding the model ancestor which has a parent equal to the workspace.

2 Likes

But what can i do if i only have the names of “D” and the part
RobloxStudioDPart

You can place an ObjectValue within “D” and set its value to the main model.

local A = Part.Parent.Parent.Parent
--which is local A = Part.D.B.A

The U can get A with that :arrow_up:
If U want to get the name only, use this instead :arrow_down: :

local A = Part.Parent.Parent.Parent.Name
--which is local A = Part.D.B.A.Name

try it

1 Like

Sorry if I didn’t explain it well, but I ment how could I get to the main Model without having a specific string for FindFirstAntecesor. :frowning:

I’m not sure what you mean by a “main model”. What characteristics classify a model as a main model?

Sorry, I was referring to the first model, the one that contains everything.
RobloxStudioAPart

This would be a good method of achieving what you are trying to go for.

1 Like