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.
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.
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.
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?
Spawn area is located in Spawns, inside Brick_Forest inside ReplicatedStorage.
Then, it gets cloned into CurrentMap. The SpawnArea is not inside CurrentMap.
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.
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)