How could i get names from a folder?

Hi, I wanted to ask how could i check all names of a folder? So like lets say example:

local folder = -- folder

local Names = --idk

part.Touched:Connect(function(hit)
if hit.name == names then
print(Names)
end
end)

How could i achive this

I’m not entirely sure what you mean with your question, but I’m assuming you’re trying to find a certain object inside the folder?

In that case you could make the if-statement say something like if folder:GetChildren()[hit.Name] to check, if the object can be found through hit.Name.

1 Like

GetChildren() returns “numberic indexed array”, so we cannot just use [hit.Name] , it will return nil even if the part is present

use this instead

local child = folder:FindFirstChild(hit.Name)
if child then 
  …
end
1 Like

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