How do Ancestors work exactly?

I’m trying to check if an instance hierarchy is a part or not.

local Prom = game:GetService("ProximityPromptService")
Prom.PromptTriggered:Connect(function(Prompt, Player)
	print(tostring(Prompt))
	if Prompt.Parent:IsA("Attachment") then
		if Prompt.Parent:GetAttribute("IsDoor") == true then
			print(tostring(Prompt:FindFirstAncestorOfClass("BasePart")))
			Door[Prompt.Type.Value](Player, Prompt:FindFirstAncestorOfClass("BasePart"))
		end
	end
end)

Like this.
image

what does it print out???

nil.

well I don’t think you can convert instance to string, try printing it’s name

Yes you can.
image

why are using “findfirstancestorofclass” instead of “findfirstancestorofwhichisa”

1 Like

Same thing. I use OfClass as a perference.
local Him = Character:FindFirstChildOfClass("Humanoid") this works.

Not the same thing. Class is “Part” and only “Part”, but IsA matches “Part”, “BasePart”, “PVInstance”, “Instance”, and "<<<ROOT>>>"

i tried this myself and it also prints nil, im gonna find out what an ancestor actually is

local Prom = game:GetService("ProximityPromptService")
Prom.PromptTriggered:Connect(function(Prompt, Player)

arent you meant to check if the instance of the prompt is triggered? change your code to

local Prom = promtlocationhere
Prom.PromptTriggered:Connect(function(Prompt, Player)

for some reason findfirstancestorofclass doesn’t work, findfirstancestor works for me

1 Like

I don’t wanna use the same script for 48 proximity prompts.

Huh, I guess it did go like that. What is a <<<ROOT>>> by the way?

Look into CollectionService. You won’t have to use the same script for 48 proximity prompts with that. In fact, thats the sole purpose behind its design

Using collectionservice would cause me to use three elseifs and three loops, I went for table functions.

I’m like you. I want my code as short as possible but unfortunately this code will end up incompatible and you will have to make sacrifices.

I honestly don’t know. It’s above Instance and it used to be listed in documentation before they decimated the content and quality of Roblox documentation for the third or fourth time. It’s some internal thing I’m sure. As far as scripting goes, the only thing that is derived from it is Instance and all of the things that derive from Instance and etc. Some other things may inherit from it behind the scenes or whatever, I don’t honestly know.
It still works though.

print(game:FindFirstChildWhichIsA("<<<ROOT>>>")) --> Workspace
1 Like

for some reason findfirstancestorofclass doesn’t work, findfirstancestor works for me

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.