Find folder name rather than item name

Right now I have been watching a tutorial on how to make a mining game for my own game (specifically tool scripts) since I’m fairly new to coding.

So far the tutorial has been helpful, but I want to be able to figure out if said item is in a folder, rather than having to go by name.

local function onTouch()
	if otherPart.Name == 'Ore1' and canMine then
		canMine = false
		print("Rock")
	end
end

So far I have tried replacing the .Name with .Parent, though that hasn’t worked
I also want it to be versatile so that it just needs to have the highest parent folder be Ore to activate

As of right now we can’t help much, what is otherPart

Oh right, another problem I didnt notice yet
and was confused by what output was outputting
Ok, new code

local function onTouch(otherPart)
	if otherPart.Name == 'Ore1' and canMine then
		canMine = false
		print("Rock")
	end
end

Basically otherPart is supposed to be the part the pickaxe collides with, so onTouch activates when the pickaxe touches an item, and otherPart is the item it touches

Okay great, so you mentioned you tried .Name and .Parent but have you tried combining them.

local function onTouch(otherPart)
	if otherPart.Parent.Name == 'TheOreParentName' and canMine then
		canMine = false
		print("Rock")
	end
end

I hadn’t tried combining them, but I did just try and it didnt work
Also, does that work if the child is a model and the parent is a folder?
(I.e. this:
image
)
Cause

if otherPart.Name == 'Ore1' and canMine then

worked, but

if otherPart.Parent.Name == 'Ores' and canMine then

didnt work

No, if you are looking for the folder, and the ore is a model, you would have to add one more .Parent:

otherPart.Parent.Parent.Name

1 Like

Hey so I just want to ask, if you want to find a parent of a parent folder, would you want to do
item.parent.parent.parent.parent
or something else?

What exactly do you mean, like you have a part in the model (first .Parent gets the model) then you get the parent folder (second .Parent gets the folder)

sorry I’m a bit late, I had dinner right after writing that
something like that
image
I want to reference the uppermost folder from the bronze typing