Need help getting the first most ancestor of a model

local partModel = part:FindFirstAncestorOfClass("Model")
local realAncestor = partModel:FindFirstAncestorOfClass("Model")

However the real ancestor line only checks another ancestor. I want it to check the first most ancestor the part.

I need to get 111, but I don’t want to depend on name
image

The image is just an example

3 Likes

I don’t entirely understand the thing you want to happen but as far as I get it, you can use something like

local parent = script.Parent
repeat
parent = parent.Parent
until parent == workspace

Idk this is as far as I understood if this is not what you meant explain a bit further

3 Likes

the code block might be parent = parent:FindFirstAncestorOfClass("Model")

2 Likes

Thank you so much, I didn’t knew the solution to this was just very simple

1 Like

but I don’t want to use Until parent == workspace I just want to get the first most which is 111. I also didn’t want to use name since it changes.

1 Like

but we need to identify the last parent tho, soooo… you can insert something into it and use the code like
until parent:FinFirstChild("TheNameOfInsertedObject")

1 Like

Ahh yes, Thank you so much. I’ve just inserted a value to the first ancestor. Was troubled for 1 hour. Thanks so much!

1 Like

I need err help again. I forgot to mention its something like this.
I basically wanted to get the parts parent but I cannot use script.Parent and repeat until parent:FindFirstChild("Parent")
local function createExplosion()

-- Creates new Explosion
local explosion = Instance.new("Explosion")
explosion.BlastRadius = 15
explosion.BlastPressure = 25000
explosion.Position = smokePart.Middle.Position

-- Connects Hit
explosion.Hit:Connect(function(part, distance)
	part.Color = Color3.new(0, 0, 0)
	
	local parent = part.Parent
	repeat
		parent = parent.Parent
	until parent == workspace


end)
explosion.Parent = game.Workspace

end

1 Like

oh wait you should have changed parent == workspace to parent.Parent == workspace,
this was a mistake of mine oops

1 Like

I’ve made a fixed, its just to find the first named ancestor, I’ve placed a value to it, Thanks for helping me

btw you can use OOP here, like

function setpart()
    --some code like you have them?
    return parent
end```

local partToChange = explosion.Hit:Connect(setpart) -- and this variable becomes the parent

ayo i might be able to make a great version i have good ideas and im decent with lua