How can i get a part inside a folder inside a folder and inside a folder?

Spawnplayers.OnServerEvent:Connect(function()

	for i, v in pairs(workspace.CurrentMap:GetChildren()) do--does not work
		print("mapspawn")
		if v.Name=="SpawnArea" then
			spawnlocation=v
		end
	end
end)

currentmap is just a folder inside Workspace.

basically, i have a map which the AreaSpawn is inside the map folder, and inside a folder named Spawns. Then I parent the folder to CurrentMap, and now im trying to get the AreaSpawn from inside the CurrentMap.

Why is this getting so many likes

23 Likes

Not completely sure what you mean, You can either try GetDescendants which gets every single object inside the chosen part/folder, or make so it looks through the folder that AreaSpawn is located in.

9 Likes

I can’t do that. The CurrentMap folder has nothing in it, so I can’t find AreaSpawn in it.

8 Likes

can u explain it more detail with a screenshot of the explorer please

8 Likes

could you explain your issue a little more detailed? or send an image of your explorer?

6 Likes

explorer:
image

hierarchy of the map

CurrentMap is just an empty folder in workspace

char.HumanoidRootPart.CFrame=spawnlocation.CFrame--spawnlocation.CFrame does not work

and the error is:attempt to index nil with ‘CFrame’

6 Likes

if you really wanted to, you could just use :FindFirstChild() to look for descendants of the item by setting its Recursive Argument to true

:FindFirstChild("AreaSpawn", true) -- looks through descendants for "AreaSpawn"

Also, you are using two different names, is it AreaSpawn or SpawnArea?

Because you’re looking for AreaSpawn in your code, but SpawnArea is in your hirearchy, not AreaSpawn, which doesnt exists because its called SpawnArea, not AreaSpawn.

5 Likes

oh, oops, I accidently changed the name, its supposed to be SpawnArea

3 Likes

is the name causing the error? i thought that was just you modifying the code when posting it here.

3 Likes

No, the name is not causing the error.

char.HumanoidRootPart.CFrame=spawnlocation.CFrame--spawnlocation.CFrame does not work

It returns the error:attempt to index nil with ‘CFrame’
So it seems like something is going on with v.

3 Likes

I dont think its that code about the CFrame, its the main code you posted. Since i dont think V’s name ever ends up being “SpawnArea”, spawnlocation is never set, therefore it stays nil, is “SpawnArea” inside a folder inside CurrentMap? Can you tell us where SpawnArea is located?

3 Likes

image
Spawn area is located in Spawns, inside Brick_Forest inside ReplicatedStorage.
Then, it gets cloned into CurrentMap. The SpawnArea is not inside CurrentMap.

3 Likes

if its not inside CurrentMap, then why are you trying to search for it in CurrentMap, This is a little too vague. Let me try to get this right

You are trying to clone SpawnArea from Brick_Forest in repstorage and move the clone into Currentmap, and then run the code that you first posted? If the code is ran before its cloned, then it will not work, You could always try using WaitForChild(“SpawnArea”) in the CurrentMap, if its being placed into there, sorry if i got this wrong.

3 Likes

For further clarification, this is what im trying to do.
image
Im trying to get the SpawnArea in the Examplemap, and inside the Currentmap folder.

1 Like

GetDescendants is supposed to get every part inside the folder, but idk if it can do it 2 times and there are no parts inside CurrentMap, but another folder, since I’m referring to CurrentMap, then I need to find the SpawnArea inside the map, which is located inside CurrentMap

oh my god, im so dumb. I just added another for loop, and it works.

code:

Spawnplayers.OnServerEvent:Connect(function()
	print("Map Loaded")
	for _, v in pairs(workspace.CurrentMap:GetChildren()) do
		print(v.Name)
		--local children=v:GetDescendants()
		local ting=v:GetChildren()
		for _,what in pairs(ting) do
			if what.Name=="SpawnArea" then
				spawnlocation=what
				print(spawnlocation.Name)
			end
		end
	end
	
	print("Map Success")
end)

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