Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

:GetChildren returning 0... how do I solve this?

Hey everyone! So I have this script, which will teleport all the players to the map. I'm selecting a random spawn for the player to spawn at. There is one issue. When I run the :GetChildren function on the spawns folder inside the map, it returns 0. No, i'm not stupid having 0 items in the folder.

Calling the function:

local map = game.Workspace.Map
	
teleportPlayers(contestants,map.Spawns:GetChildren())

The "teleportPlayers" function:

local function teleportPlayers(availablePlayers,spawns) -- both are tables
	for _, player in pairs(availablePlayers) do
		if player.Character then
			if player.Character:FindFirstChild("HumanoidRootPart") then
				player.Character.HumanoidRootPart.CFrame = spawns[math.random(1,#spawns)].CFrame + Vector3.new(0,5,0)
			end					
		end	
	end
end

Even though I have tons of scripting knowlage, I for some reason don't know how to solve this. Please help lol

1 comment

0

can you insert all of your script?

1 answer

I can't give you a certain answer because you only showed a portion of your script. But I hope this helps you figure it out:

local players = game:GetService("Players")
local map = game.Workspace.Map
local contestants = {}
local spawns = {workspace.spawn1,workspace.spawn2,workspace.spawn3} --Change this.

for i, player in pairs(players:GetChildren()) do
	contestants.Insert(player)
end

for i, player in pairs(contestants) do
	if player.Character then
		local humanoidrootpart = player.Character.HumanoidRootPart
		humanoidrootpart.CFrame = spawns[math.random(1,#spawns)].CFrame + Vector3.new(0,6,0)
	end
end

This discussion is preserved as it was. New answers, comments, and votes are closed.