Server Script not recognizing parts in workspace folder

I am trying to create a randomized spawn for a map in my game, but the script does not recognize that the parts even exist. I printed the table length and table, both were 0/no elements.

Here’s my code:

			local MapSpawns = game.Workspace:WaitForChild("MountainMap"):WaitForChild("SpawnLocations"):GetChildren()
			print("LENGTH OF SPAWN LOCATIONS = " .. tostring(#MapSpawns), MapSpawns)
			plr.Character:MoveTo(MapSpawns[math.random(1, #MapSpawns)].Position)

proof that its in worspace:
BRUH

1 Like

Have you tried to replace :WaitForChild with :FindFirstDescendant?

In all of the uses of :WaitForChild()?

Yes, you don’t need to wait for the child as its workspace assets should already be loaded in before the character.

Maybe it will work better like that :

local Map = game.Workspace:WaitForChild("MountainMap")
local Spawns = Map:WaitForChild("SpawnLocations")
print("lenght : "..#Spawns)
local Character = plr.Character
Character:PivotTo(Spawns[math.random(1, #Spawns)].CFrame)

I don’t believe there’s enough information to accurately debug this, but here’s a checklist you can quickly run through if you have yet to:

  • Ensure the hierarchy you’re following is the correct one
    • There’s not multiple MountainMap groups or SpawnLocations folders
  • All of the spawns are present whenever you’re getting children
    • They have Archivable set to true
    • They’re not falling out of the world (CanCollide = false, Anchored = false)
    • They exist on the server and not just the client
  • Get and print the spawns after a few seconds of waiting, to determine if the original* script is running before they can be loaded in

ps: use the workspace global instead of game.Workspace for convenience
edit*