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

Attempt to index nil with 'GetChildren'?

	local nowMap = workspace.Maps:GetChildren()

	local players = game.Players:GetChildren()
	for i = 1,#players do
		
		if players[i].Character ~= nil then
			local nowMap = nowMap.MapTeleports:GetChildren()
			local spawnLocation = math.random(1,#nowMap.MapTeleports:GetChildren())
			players[i].Character:MoveTo(spawnLocation.Position)
			players[i].Character.Parent = workspace.Ingame
		end
	end

4 comments

0

Wait Which Line Is The Error in? There Are More GetChildren()'s then 1

0

line 07

0

You made a very simple mistake its because MapTeleport hasn't been defined. What I mean by that is your storing a function :GetChildren to your script which will cause an error

0

And its best to use a generic for loops as this will repeat the action for a period of time. And loop through the objects.

4 answers

You're problem is coming from this line: local nowMap = workspace.Maps:GetChildren()

In line 7, you attempt to use this variable nowMap to access the spawning ports but instead you are trying to access a Table which causes you to error. :GetChildren()creates a table of all the children of that part, but doesn't apply to specific part. See what I mean?

You'll need to change or add a variable that references the specifc map, or the spawn ports, so you can appropriately acess them. So by, let's say, changing your nowMap variable by removing the :GetChildren() could solve your issue or creating a new variable that is assigned to the spawn ports (without the :GetChildren() part). Hope this Helps! :)

-Audiimo

local nowMap = workspace.Maps:GetChildren()

local players = game.Players:GetChildren()
for i = 1,#players do

    if players[i].Character ~= nil then
        local nowMap = nowMap.MapTeleports:GetChildren()
        local spawnLocation = math.random(1,#nowMap.MapTeleports:GetChildren())
        players[i].Character:MoveTo(spawnLocation.Position)
        players[i].Character.Parent = workspace.Ingame
    end
end

im not sure what u are trying to do here u get the children of nowmap in the firstline and then u try to use nowmap again so ur bassicly doing this

workspace.Maps:GetChildren().MapTeleports:GetChildren()

what are u exactly trying to do here? if u just want to get the children of MapTeleports u could do this

workspace.Maps.MapTeleports:GetChildren()

Hmm i Noticed That You Refrenced nowMap To Multiple Objects Not Just One


local nowMap = worspace.Maps:GetChildren()

Is That Intended? If It Is Then, You Can Use In Pairs Loop Instead, Reply With More Info About Your code And i'll Hopefully Respond With A Solution. , Theres Another Mistake You Refrenced nowMap Twice Which Changed nowMap's Original Refrence Perhaps Change line (07) local nowMap to another name? Because I Dont Think You Can Refrence One local to More than One Object.

3 comments

0

This code is wrong.

0

You misspelled workspace

0

And I believe you can store multiply variables.

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